Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Discriminated polymorphism does not populate anyOf and oneOf, in contrast with Swagger documentation #3166

Open
ldeluigi opened this issue Nov 22, 2024 · 0 comments
Labels
bug help-wanted A change up for grabs for contributions from the community

Comments

@ldeluigi
Copy link

Problem

The problematic line is this:

GenerateConcreteSchema(knownTypeDataContract, schemaRepository);

This line properly generates subtype definitions but doesn't populate any of the anyOf/oneOf properties, resulting in a "broken" swagger document.

Quoting the Swagger doc:

The discriminator is used with anyOf or oneOf keywords only.

Side note

This also breaks openapi based code generators that properly support polymorphism honoring discriminators

Solution

Use the result of the invocation of GenerateConcreteSchema, filling the anyOf/oneOf field. More specifically, we think that oneOf better suits this use case.

@ldeluigi ldeluigi changed the title Discriminated polymorphism does not populate anyOf and oneOf, in contrast with Swagger documentation [Bug] Discriminated polymorphism does not populate anyOf and oneOf, in contrast with Swagger documentation Nov 22, 2024
@martincostello martincostello added bug help-wanted A change up for grabs for contributions from the community labels Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help-wanted A change up for grabs for contributions from the community
Projects
None yet
Development

No branches or pull requests

2 participants