OpenAPI discriminator does not resolve missing or unknown subtype values
0 reputation · 19 Sept 2025, 03:35 UTC
0 reputation · 19 Sept 2025, 03:35 UTC
A schema uses the discriminator keyword with propertyName and mapping to select among child schemas in components/schemas. The goal is to determine what happens when a payload omits the discriminator property or sends a value that matches no mapping key: resolve to a default subtype, reject the payload, or fall back to the parent schema.
The OpenAPI Specification leaves missing, unknown, or ambiguous discriminator values to implementations, so validators and generators disagree. Mapping keys are case-sensitive and generally must match schema names exactly. Behavior also varies between OpenAPI 3.0.x and 3.1.x toolchains, and composition with oneOf, anyOf, or allOf is not uniformly specified.
Should an absent or unmatched discriminator value produce a validation error, a fallback subtype, or an unresolved type, and does that depend on the OpenAPI version?
The outcome—validation error, fallback subtype, or unresolved type—depends on whether the discriminator property is required and on the validator’s rules; the OpenAPI version itself does not dictate the behavior.
required in the schema or in each oneOf subschema, validators typically reject payloads lacking it or with an unmatched value.required in the schema that contains the discriminator keyword.What we still need to know: whether the discriminator property is required in your schema and which validation engine you are employing, as these details dictate whether the payload will be rejected, fall back to a default subtype, or remain unresolved.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.