Swashbuckle.AspNetCore icon indicating copy to clipboard operation
Swashbuckle.AspNetCore copied to clipboard

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

Open ldeluigi opened this issue 3 months ago • 0 comments

Problem

The problematic line is this: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/e727e8d53cd9f7edebe5faa6b8bf183e19afb0c6/src/Swashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/SchemaGenerator.cs#L416

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 avatar Nov 22 '24 14:11 ldeluigi