openapi-core
openapi-core copied to clipboard
Discriminator for oneOf schemas ignored
If a discriminator is set for a list of oneOf schemas only the matching schema should be validated against and therefore useful errors can be provided:
schema
requestBody:
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/cat_type'
- $ref: '#/components/schemas/dog_type'
discriminator:
propertyName: type
mapping:
cat: '#/components/schemas/cat_type'
dog: '#/components/schemas/dog_type'
request
{'type': 'dog' ...}
If the request is invalid the validator raises: "Exactly one valid schema should be valid, None found."
But if there's a discriminator we know which schema to validate against and could provide a useful error message. Such as what property is missing or invalid.
See https://github.com/p1c2u/openapi-core/issues/257#issuecomment-964053231 for a workaround.