Document-level pre-pass for OpenAPI discriminators that are declared
on a base schema and inherited by subtypes via allOf.
The per-node normaliseOpenApi30Discriminator only handles
discriminators that already sit alongside oneOf/anyOf. For the
canonical "Cat extends Pet" pattern — where Pet carries the
discriminator and Cat/Dog reference Pet via allOf — the
discriminator is silently lost. This pre-pass:
Injects the discriminator const on each subtype's local
properties (so a direct render of the subtype validates the
discriminator value correctly).
Synthesises a oneOf on the base whenever it lacks one, listing
each subtype as { $ref, properties: { propertyName: { const } } }.
The per-node discriminator transform then sees oneOf and clears
the discriminator keyword, and the walker's
detectDiscriminated finds the per-option consts.
Mutates a shallow clone of components/schemas — the input document
is never modified.
Document-level pre-pass for OpenAPI discriminators that are declared on a base schema and inherited by subtypes via
allOf.The per-node normaliseOpenApi30Discriminator only handles discriminators that already sit alongside
oneOf/anyOf. For the canonical "Cat extends Pet" pattern — wherePetcarries the discriminator andCat/DogreferencePetviaallOf— the discriminator is silently lost. This pre-pass:conston each subtype's localproperties(so a direct render of the subtype validates the discriminator value correctly).oneOfon the base whenever it lacks one, listing each subtype as{ $ref, properties: { propertyName: { const } } }. The per-node discriminator transform then seesoneOfand clears thediscriminatorkeyword, and the walker'sdetectDiscriminatedfinds the per-optionconsts.Mutates a shallow clone of
components/schemas— the input document is never modified.