Skip to content

Add support for discriminator in OpenAPI v3#2151

Open
lukasab wants to merge 1 commit intoswaggo:v2from
lukasab:feat/v2-polymorphism-discriminator-support
Open

Add support for discriminator in OpenAPI v3#2151
lukasab wants to merge 1 commit intoswaggo:v2from
lukasab:feat/v2-polymorphism-discriminator-support

Conversation

@lukasab
Copy link
Copy Markdown

@lukasab lukasab commented Mar 13, 2026

Describe the PR
Adds a new @Discriminator route-handler annotation for OpenAPI v3. When a response (or request body) uses oneOf polymorphism (multiple @Success annotations with the same status code), a discriminator object can now be declared to tell clients which concrete type to use at runtime.

Relation issue
#2150 #829

Additional context
Builds on the existing oneOf support introduced in #1870 and extended in #2059. The discriminator should only be applied to schemas that already contain a oneOf composition, as per the OpenAPI 3.0 spec.

Implementation notes

  • Follows the same deferred-processing pattern as @Produce
  • discriminatorInfo *parsedDiscriminator is stored on OperationV3 to bridge the two phases. Open to feedback on whether there's a better place for this — it felt slightly out of place on the struct but couldn't find a cleaner alternative given the parse ordering constraints.
  • Declaring @Discriminator twice on the same operation returns an error rather than silently overwriting.
  • Applied to both responses and request body content.

@lukasab lukasab force-pushed the feat/v2-polymorphism-discriminator-support branch from 80327bc to f2e970a Compare March 13, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant