You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update OpenAPI document generation to correctly represent C# union types in the generated specification. Union types should produce anyOf schemas composed from their case types.
Schema generation path:
STJ's JsonSchemaExporter already emits anyOf for union types (driven by JsonTypeInfo.UnionCases). The OpenAPI layer uses JsonSchemaExporter under the hood (OpenApiSchemaService), so the raw schema should come out correctly. The work is ensuring the OpenAPI layer correctly maps the STJ schema output to OpenAPI constructs.
No discriminator:
Unlike [JsonPolymorphic] types which generate oneOf + discriminator in OpenAPI, unions should produce anyOf with no discriminator object. This matches STJ's transparent serialization (no $type on the wire).
Response metadata expansion:
When an endpoint returns a union type, the response metadata currently shows the union type itself. Two approaches:
Option A: Keep union as a single response type, let the schema layer expand to anyOf via JsonSchemaExporter — simpler, schema is auto-generated
Update OpenAPI document generation to correctly represent C# union types in the generated specification. Union types should produce
anyOfschemas composed from their case types.Related: #55412, #56177
Expected behavior
Given an endpoint:
The OpenAPI spec should produce:
For a simple value union:
Areas to investigate
Schema generation path:
STJ's
JsonSchemaExporteralready emitsanyOffor union types (driven byJsonTypeInfo.UnionCases). The OpenAPI layer usesJsonSchemaExporterunder the hood (OpenApiSchemaService), so the raw schema should come out correctly. The work is ensuring the OpenAPI layer correctly maps the STJ schema output to OpenAPI constructs.No discriminator:
Unlike
[JsonPolymorphic]types which generateoneOf+ discriminator in OpenAPI, unions should produceanyOfwith no discriminator object. This matches STJ's transparent serialization (no$typeon the wire).Response metadata expansion:
When an endpoint returns a union type, the response metadata currently shows the union type itself. Two approaches:
anyOfviaJsonSchemaExporter— simpler, schema is auto-generatedProducesResponseTypeMetadataentries at the metadata layer (leveraging MVC+OpenAPI: Support multipleProducesfor same status code / content-type #65650 infrastructure) — more explicit, each case type appears separately in the responseRequest body schemas:
When a union is a request body parameter, the schema should similarly show
anyOffor the parameter type.