Skip to content

OAS 3.1/3.2 discriminator is annotation-only#279

Merged
p1c2u merged 1 commit intomasterfrom
fix/oas31-discriminator-annotation-only
Mar 7, 2026
Merged

OAS 3.1/3.2 discriminator is annotation-only#279
p1c2u merged 1 commit intomasterfrom
fix/oas31-discriminator-annotation-only

Conversation

@p1c2u
Copy link
Collaborator

@p1c2u p1c2u commented Mar 7, 2026

The OAS 3.1 validator was inheriting custom oneOf/anyOf/allOf handlers that replace standard JSON Schema composition with discriminator-based $ref resolution (OAS 3.0 semantics). In OAS 3.1/3.2, discriminator is a pure annotation; composition validation is governed entirely by oneOf/anyOf/allOf. Removed those overrides so OAS 3.1/3.2 uses Draft 2020-12 semantics directly.

# Before: OAS31Validator with discriminator would silently attempt ref resolution
schema = {
    "$schema": "https://spec.openapis.org/oas/3.1/dialect/2024-11-10",
    "oneOf": [
        {"type": "object", "properties": {"petType": {"const": "cat"}, "meow": {"type": "string"}}, "required": ["petType", "meow"]},
    ],
    "discriminator": {"propertyName": "petType"},
}
v = OAS31Validator(schema)
list(v.iter_errors({"petType": "cat", "meow": "purr"}))
# Was: [ValidationError: "... reference '#/components/schemas/cat' could not be resolved"]
# Now: []  — discriminator ignored, oneOf validates normally

@p1c2u p1c2u force-pushed the fix/oas31-discriminator-annotation-only branch from 924cb84 to 71249e7 Compare March 7, 2026 22:00
@p1c2u p1c2u merged commit 3c71e8c into master Mar 7, 2026
16 checks passed
@p1c2u p1c2u deleted the fix/oas31-discriminator-annotation-only branch March 7, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant