-
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
OneOfValidator is filtering out the required errors if all the oneOf schemas are having the issues. #678
Comments
I think your problem rather is that the existing implementation would not expect the I think that the original code by @ksychla would work fine in case there were only the two "is required" errors, because in this case, that's exactly the special case which makes lines 204-206 of the original commit remove any "not required" errors from the validation messages...
So it might be that the question you'd need to ask rather is: Why do we see the "object found, string expected" message here although it is NOT required or even expected by the schema at all that "innerObject" would be a string - it can as well be an object (as the "oneOf" specifies). Hope I've succeeded to describe it well enough to be generally understandable (sorry, I'm no native speaker). |
@rahultokase @AndreasALoew I think the following should be the returned error given the condition failFast is true or false. If failFast == true If failFast == false The first error "$.outerObject.innerObject: object found, string expected" should not show up as you do provide an object although it is empty. What do you think? |
@stevehu , as I already tried to state yesterday, I also think that the "object found, string expected" is the root cause of the issue here, not the logic as implemented by @ksychla . We are always using the validator with failFast == false here, so I cannot really comment which of the two "is missing but required" errors should be the one to be thrown with failFast == true, but other than that, I fully agree with your analysis. |
We are using the following schema. In the following schema we have
{ "$schema": "http://json-schema.org/draft-07/schema#", "$id": "https://example.com/issue-470.json", "title": "OneOf validation message", "description": "Test description", "type": "object", "properties": { "outerObject": { "type": "object", "properties": { "innerObject": { "oneOf": [ { "type": "string" }, { "type": "object", "properties": { "value": { "type": "string" }, "unit": { "type": "string" } }, "additionalProperties": false, "required": [ "value", "unit" ] } ] } } } }, "additionalProperties": false }
the above schema was validated with below json data.
{ "outerObject": { "innerObject": {} } }
The errors given by oneOfValidator are
$.letterSpacing.wide: object found, string expected
The expected one was
$.outerObject.innerObject: object found, string expected
$.outerObject.innerObject.value: is missing but it is required
$.outerObject.innerObject.unit: is missing but it is required
After Inspecting the oneOfValidator code we figured out that
The text was updated successfully, but these errors were encountered: