schema-components - v3.7.0
    Preparing search index...

    Function detectDiscriminated

    • Detect oneOf where every option is an object with a property that has a const value → discriminated union.

      When options carry inconsistent discriminator candidates (e.g. one uses kind while another uses type) detection fails and a discriminator-inconsistent diagnostic is emitted so callers can see why the union falls back to a generic oneOf.

      When two or more options share the same discriminator const value, the union is still treated as discriminated — the first-match behaviour in resolveDiscriminatedActive (in core/unionMatch.ts) resolves the active option — but a discriminator-duplicate diagnostic is emitted so the unreachable branch is visible to the consumer. Changing the behaviour to fall back to a generic union would be a silent regression for the much commoner case of two intentionally-identical discriminator values appearing in distinct sub-schemas (e.g. an allOf-driven hierarchy where the base option duplicates the leaf).

      Parameters

      Returns Discriminated | undefined