-
Notifications
You must be signed in to change notification settings - Fork 1
Conversation
The template models had no structural representation of OpenAPI polymorphic schemas (oneOf/anyOf/allOf). The workaround was a simplify-polymorphic-schemas patch 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 string
Model
OneOf/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 present
Property
- Added
Required,ReadOnly,WriteOnly boolfrom the source schema
BuildComponentModels rewrite
Each schema now follows a dedicated branch instead of collapsing into a flat merge:
- oneOf / anyOf -- each
*SchemaProxyresolved to aCodeType; discriminator mapping resolved toCodeTypevalues via the component schema registry - allOf -- referenced sub-schemas -
AllOf []CodeTypeparents; inline sub-schemas - properties merged directly (dedup-aware, inheritingrequiredfrom both the root schema and the inline sub-schema) - object / array / fallback -- unchanged, only reached when no polymorphic case applies
Extracted helpers: buildModelProperties (sets Required/ReadOnly/WriteOnly, handles deduplication across allOf merges) and buildDiscriminatorModel (resolves $ref mapping entries to full CodeType values).
Default patches
Removed simplify-polymorphic-schemas from DefaultCodeGenerationPatches -- it is no longer needed as a default; it remains available for opt-in use.
Example -- discriminator-based oneOf
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
discriminator:
propertyName: petType
mapping:
cat: '#/components/schemas/Cat'
dog: '#/components/schemas/Dog'
Produces a PetDto model with:
IsOneOf: true
OneOf: [CodeType{Name:"CatDto"}, CodeType{Name:"DogDto"}]
Discriminator: {
PropertyName: "petType",
Mapping: {
"cat": CodeType{Name:"CatDto", QualifiedType:"CatDto", ...},
"dog": CodeType{Name:"DogDto", QualifiedType:"DogDto", ...},
}
}
We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
Co-authored-by: PhilippHeuer <10275049+PhilippHeuer@users.noreply.github.com>