Skip to content

Comments

Discriminator handling for non-object instances#249

Merged
p1c2u merged 1 commit intomasterfrom
fix/discriminator-handing-for-non-object-instances
Feb 20, 2026
Merged

Discriminator handling for non-object instances#249
p1c2u merged 1 commit intomasterfrom
fix/discriminator-handing-for-non-object-instances

Conversation

@p1c2u
Copy link
Collaborator

@p1c2u p1c2u commented Feb 20, 2026

This pull request improves the handling and validation of the discriminator keyword in OpenAPI schema validation. The main focus is on ensuring that the discriminator logic is only applied to objects and on adding corresponding test coverage for this scenario.

Discriminator validation improvements:

  • Updated handle_discriminator in openapi_schema_validator/_keywords.py to check if the instance is an object before applying discriminator logic, yielding a ValidationError if not.

Test coverage enhancements:

  • Added a test in tests/integration/test_validators.py to assert that a ValidationError is raised with the correct message when the discriminator is used on a non-object instance.

@p1c2u p1c2u force-pushed the fix/discriminator-handing-for-non-object-instances branch from 028e5c9 to f5b364f Compare February 20, 2026 16:32
@p1c2u p1c2u merged commit f203cde into master Feb 20, 2026
14 checks passed
@p1c2u p1c2u deleted the fix/discriminator-handing-for-non-object-instances branch February 20, 2026 16:33
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