Extend template models with native oneOf/anyOf/allOf support and discriminator CodeType mapping#3
Draft
Extend template models with native oneOf/anyOf/allOf support and discriminator CodeType mapping#3
Conversation
…ve simplify-polymorphic-schemas from defaults Co-authored-by: PhilippHeuer <10275049+PhilippHeuer@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Extend internal template models for dynamic structures
Proper oneOf/anyOf/allOf support in template models; remove simplify-polymorphic-schemas workaround
Feb 25, 2026
Co-authored-by: PhilippHeuer <10275049+PhilippHeuer@users.noreply.github.com>
Copilot
AI
changed the title
Proper oneOf/anyOf/allOf support in template models; remove simplify-polymorphic-schemas workaround
Extend template models with native oneOf/anyOf/allOf support and discriminator CodeType mapping
Feb 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The template models had no structural representation of OpenAPI polymorphic schemas (
oneOf/anyOf/allOf). The workaround was asimplify-polymorphic-schemaspatch that flattened everything into a single object, discarding discriminator info and making it impossible to generate correct language-level union/inheritance constructs (e.g. Jackson@JsonSubTypes).Model changes
DiscriminatorModel(new type)PropertyName string— the JSON property carrying the type tagMapping map[string]CodeType— discriminator value → fully resolvedCodeType(name, qualified type, import path, etc.), giving templates access to all type metadata rather than a bare class name stringModelOneOf/AnyOf/AllOf []CodeType— resolved variant/parent type references (replaces unused[]Model)IsOneOf / IsAnyOf / IsAllOf bool— flags for template branchingDiscriminator *DiscriminatorModel— populated when a discriminator is presentPropertyRequired,ReadOnly,WriteOnly boolfrom the source schemaBuildComponentModelsrewriteEach schema now follows a dedicated branch instead of collapsing into a flat merge:
*SchemaProxyresolved to aCodeType; discriminator mapping resolved toCodeTypevalues via the component schema registryAllOf []CodeTypeparents; inline sub-schemas → properties merged directly (dedup-aware, inheritingrequiredfrom both the root schema and the inline sub-schema)Extracted helpers:
buildModelProperties(setsRequired/ReadOnly/WriteOnly, handles deduplication across allOf merges) andbuildDiscriminatorModel(resolves$refmapping entries to fullCodeTypevalues).Default patches
Removed
simplify-polymorphic-schemasfromDefaultCodeGenerationPatches— it is no longer needed as a default; it remains available for opt-in use.Example — discriminator-based oneOf
Produces a
PetDtomodel with:💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.