Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report an error when the discriminator property is not defined in 'oneOf' the schema types? #344

Closed
senthilkumarmohan opened this issue Nov 8, 2018 · 3 comments

Comments

@senthilkumarmohan
Copy link
Contributor

Should we report an error when the discriminator property is not defined in 'oneOf' the schema types? in the below example, pet2 doesn't have the expected discriminator property.

responses:
'200':
description: pet response
content:
application/json:
schema:
oneOf:
- "$ref": '#/components/schemas/pet1'
- "$ref": '#/components/schemas/pet2'
discriminator:
propertyName: petType
components:
schemas:
pet1:
type: object
required:
- id
properties:
id:
type: integer
format: int64
petType:
type: string
pet2:
type: object
required:
- id
properties:
id:
type: integer
format: int64

@senthilkumarmohan senthilkumarmohan changed the title Should we report an error when the discriminator property is not defined in 'oneOf' the schema types? Report an error when the discriminator property is not defined in 'oneOf' the schema types? Nov 8, 2018
@PerthCharern
Copy link
Contributor

From the spec, we might be able to be even stricter:

https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#composition-and-inheritance-polymorphism

"... As such, the discriminator field MUST be a required field. There are are two ways to define the value of a discriminator for an inheriting instance."

Would you like to send out a PR? :)

@senthilkumarmohan
Copy link
Contributor Author

Thanks for your response. I am working on it - will submit a PR soon.

@senthilkumarmohan
Copy link
Contributor Author

@PerthCharern, i have submitted a PR for this. Please can you review?

PerthCharern added a commit that referenced this issue Nov 15, 2018
…r-when-OneOf-schema-doesnt-have-the-discriminator-property

Fix #344

Validate `anyOf` and `oneOf` contains the property specified in the `discriminator`.
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

No branches or pull requests

2 participants