Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Extend template models with native oneOf/anyOf/allOf support and discriminator CodeType mapping#3

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/extend-openapi-template-models
Draft

Extend template models with native oneOf/anyOf/allOf support and discriminator CodeType mapping#3
Copilot wants to merge 3 commits intomainfrom
copilot/extend-openapi-template-models

Conversation

Copy link

Copilot AI commented Feb 25, 2026 *
edited
Loading

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 tag
  • Mapping map[string]CodeType -- discriminator value - fully resolved CodeType (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 branching
  • Discriminator *DiscriminatorModel -- populated when a discriminator is present

Property

  • Added Required, ReadOnly, WriteOnly bool from the source schema

BuildComponentModels rewrite

Each schema now follows a dedicated branch instead of collapsing into a flat merge:

  • oneOf / anyOf -- each *SchemaProxy resolved to a CodeType; discriminator mapping resolved to CodeType values via the component schema registry
  • allOf -- referenced sub-schemas - AllOf []CodeType parents; inline sub-schemas - properties merged directly (dedup-aware, inheriting required from 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

Pet:
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.

Copilot AI assigned Copilot and PhilippHeuer Feb 25, 2026
Copilot started work on behalf of PhilippHeuer February 25, 2026 21:00 View session
...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
Copilot finished work on behalf of PhilippHeuer February 25, 2026 21:17
Copilot started work on behalf of PhilippHeuer February 25, 2026 21:48 View session
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
Copilot finished work on behalf of PhilippHeuer February 25, 2026 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants