-
Notifications
You must be signed in to change notification settings - Fork 324
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
OneOf Validation removes validations, making invalid data appear valid #653
Comments
@kamtschatka I have reviewed the changes for #535 and the fix makes sense. Could you please elaborate a little bit more on what was wrong with that PR? Or better yet, summit a PR to help the discussion? Thanks. |
The fix only makes sense for this particular use case, and only because the schema in the sample for #535 is not created properly. The schema said the following: What you can however do is the following: This change for #535 tries to perform some magic in the validations to narrow it down(which is not actually specified in the schema definiton), which breaks the validation results for other scenarios. |
I am with you. We shouldn't have customized code to handle a particular scenario. Is it possible for you to submit a PR to get it fixed? Thanks. |
@kamtschatka Do these messages meet your needs? json-schema-validator/src/test/resources/draft7/issue653.json Lines 82 to 86 in 284e952
|
The first 2 look good, but I am wondering why the third one is there? The "false" condition is part of the else branch, so shouldn't it be omittted? |
I updated the OneOfValidator; I still have to tackle the IfValidator. If this is good for you, I'll close this issue. It would be nice if you reported another issue on what you expect from |
Closing as resolved |
We are working on validating an array of different kinds of events, that are distinguished by an "event.type" property.
For a reproducer, I have recreated it with a "pet_type" property.
There is the type Cat and Dog. If I just put them as possible types into the array, the passed in JSON gets validated against each type separately and we will get all validation errors for all types, which makes the error very hard to find.
To narrow it down, we are using "if/then/else" to narrow down the type based on the "pet_type" beforehand:
I then pass in this JSON for validations:
What I expect it to complain about:
When I run this on https://www.jsonschemavalidator.net/, everything shows up as expected.
When I run it with the json-schema-validator, the only message I get is "Boolean schema false is not valid". This is basically the optional error I have listed above.
When I debug through the validator, I can see that the "OneOfValidator" actually detects the problem with the "age" property being required, when it is missing. The validation error gets filtered out in the OneOfValidator though, because of #535.
The problem with "hunts" being a string and not a boolean is also detected and filtered out, but I did not debug into it further.
In my opinion the change for issue 535 is invalid and should be removed again. The JSON does not match against either of the provided schemas, so all the errors should be shown. https://www.jsonschemavalidator.net shows the same outcome as json-schema-validator showed before the change.
To get a better validation result for the sample from issue 535, the "if/then/else" mechanism should probably be used.
The text was updated successfully, but these errors were encountered: