-
-
Notifications
You must be signed in to change notification settings - Fork 876
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
Support OpenAPI discriminator keyword together with oneOf #1119
Comments
Even without discriminator, couldn't/shouldn't it be possible to disambiguate between various schemas in a oneOf, and validate the sub-elements of the matching schema? By definition, the oneOf should not be valid if there is no differentiating property(ies) between the schemas. |
oneOf by definition should fail if the data instance is valid against none or more than one sub-schema. In general case, it is not possible to determine by schema analysis (as you suggest) so ajv has to validate against ALL subschemas when oneOf is used. |
Gotcha. What I was getting at was that if the property names all line up with one of the schemas, but a value violates a regex pattern, for example, then I would hope to have an error generated indicating that. This actually does seem to be happening. There are also other errors for not matching any of the other schemas. Which is also expected. I think my confusion was about oneOf matching a schema based solely on which properties exist, vs. whether the values also meet the criteria defined for those properties. |
That is correct, but such conclusion is only possible for a subset of possible schemas, but not for all schemas. So this approach would only work sometimes, not always.
Think about discriminator keyword as an equivalent of a compiler instruction that while does not change the outcome (validation result), helps to optimise and short-circuit the generated lower level code (Javascript) without the need for the compiler (ajv) to do the analysis of code (schema) - that may be complex in some cases and impossible in general case.
Hope it makes sense.
… On 13 Nov 2019, at 15:23, thetumper ***@***.***> wrote:
Gotcha. What I was getting at was that if the property names all line up with one of the schemas, but a value violates a regex pattern, for example, then I would hope to have an error generated indicating that. This actually does seem to be happening. There are also other errors for not matching any of the other schemas. Which is also expected.
I think my confusion was about oneOf matching a schema based solely on which properties exist, vs. whether the values also meet the criteria defined for those properties.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
released in v8.0.0-beta.2 |
v8 now released as the main version: https://ajv.js.org/v6-to-v8-migration.html |
Thank you! |
* discriminator keyword, ajv-validator#1119 (WIP) * OpenAPI discriminator, tests, ajv-validator#1119 * docs: discriminator
What problem do you want to solve?
The second can be addressed separately
The solution requirements?
Will you be able to implement it?
Yes, with the right incentive :) PR is welcome.
The text was updated successfully, but these errors were encountered: