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

Validation of schema with discriminator property #141

Closed
Xbloud opened this issue Nov 10, 2020 · 3 comments
Closed

Validation of schema with discriminator property #141

Xbloud opened this issue Nov 10, 2020 · 3 comments
Labels
question Issues that look for answers.

Comments

@Xbloud
Copy link

Xbloud commented Nov 10, 2020

I use the OpenAPI's discriminator property in my JSON schemas and I get the following error when compiling schemas:
ERROR Error: [discriminator]: need propertyName, oneOf OR anyOf at ConfigBase#
It seems that your discriminator property checking does not cover all valid options. Is there any option to disable the "discriminator" property checking/handling?

JSON schemas:
"Base" : { "type" : "object", "properties" : { "description" : { "type" : "string", }, "dp" : { "type" : "string", } }, "discriminator" : { "propertyName" : "dp" } },

"IndividualBase" : { "type" : "object", "allOf" : [ { "$ref" : "Base#" }, { "type" : "object", "properties" : { "key" : { "type" : "string", } } } ] },

@jchook
Copy link

jchook commented Nov 19, 2020

Your issue may relate to support for only a strict subset of discriminator.

This may not relate to your problem, but I wanted to note that OpenAPI 3.0.x does not match JSON Schema exactly and you must first convert it using e.g. openapi-schema-to-json-schema. You must also use the draft04 JSON Schema spec.

@ChALkeR ChALkeR added the question Issues that look for answers. label Oct 7, 2022
@ChALkeR
Copy link
Contributor

ChALkeR commented Oct 7, 2022

Sorry, I missed this issue.

Is there any option to disable the "discriminator" property checking/handling?

The problem is that the behavior of discriminator is underspecified, and outside the strict subset mentioned above, that behavior is non-obvious.

Disabling coherence checks on schema could lead to unexpected and/or unspecified behavior.

More specifically: in the schema given above, the behavior apparently expected from the allOf usage contradicts the upstream JSON Schema spec. It should have been anyOf or oneOf.

As a rule of thumb, everything that passes with discriminator should also pass without it, which is something this schema does not follow.

Covering underspecified or contradictory cases of discriminator is not planned.

@ChALkeR
Copy link
Contributor

ChALkeR commented Oct 7, 2022

Closing as answered, please feel free to comment if there are more questions.

@ChALkeR ChALkeR closed this as completed Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

3 participants