openapi-core icon indicating copy to clipboard operation
openapi-core copied to clipboard

Discriminator for oneOf schemas ignored

Open smarlowucf opened this issue 6 years ago • 1 comments

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.

smarlowucf avatar Jul 26 '18 21:07 smarlowucf

See https://github.com/p1c2u/openapi-core/issues/257#issuecomment-964053231 for a workaround.

ngnpope avatar Nov 09 '21 11:11 ngnpope