Skip to content

Add support for discriminator in OpenAPI v3 - #2151

Merged
ubogdan merged 1 commit into
swaggo:v2from
lukasab:feat/v2-polymorphism-discriminator-support
Apr 9, 2026
Merged

ubogdan merged 1 commit into
swaggo:v2from
lukasab:feat/v2-polymorphism-discriminator-support

Conversation

@lukasab

@lukasab lukasab commented Mar 13, 2026 •

Copy link
Copy Markdown

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

@ubogdan ubogdan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ubogdan
ubogdan merged commit 575d84f into swaggo:v2 Apr 9, 2026
14 checks passed
@ubogdan

ubogdan commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

@lukasab Thanks for your contribution.

@kundkingan

Copy link
Copy Markdown

@ubogdan New release coming out soon?

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.

3 participants

⌂ 换网址