You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using "anyOf" or "oneOf" gives an incorrect message by always indicating the the attribute defined in the first index of the anyOf or oneOf array is required.
Code used to validate and show errors reported: result, err := gojsonschema.Validate(schemaLoader, requestLoader) if !result.Valid() { for _, err := range result.Errors() { log.Println() } }
Actual Error Message:
options: Must validate at least one schema (anyOf)
layers: one is required
The text was updated successfully, but these errors were encountered:
Error messages for anyOf and oneOf are tricky as it's not always as clear what the error message should be. If you have multiple clauses in a oneOf and none of them pass and then put all errors of all clauses in the resulting error set that can lead to a massive amount of errors. Most of those errors will be nonsense as only one of them needs to be satisfied, and in the case of oneOf, satisfying too many will lead to a different error.
Therefore the original author chose to only return one single error for anyOf and oneOf by heuristically looking for the clause that matched most closely (has the least amounts of errors), and only return the errors from that clause. However in practice (and also your example), all clauses are equally unsatisfied and therefore the first one is chosen.
Most implementations, like https://www.jsonschemavalidator.net/ do this differently. I'm not sold on the way it's currently done in gojsonschema, but I don't hate it either. If anyone convinces me that this really should be changed and submits a PR I'm open to it.
Using "anyOf" or "oneOf" gives an incorrect message by always indicating the the attribute defined in the first index of the
anyOf
oroneOf
array is required.Given the following schema:
{ "$schema":"http://json-schema.org/draft-07/schema#", "$id":"test.schema.json", "title":"test", "type": "object", "properties": { "options": { "type":"object", "anyOf": [ {"required": ["one"]}, {"required": ["two"]} ], "properties":{ "foo": { "type":"object" }, "bar": { "type":"object" } } } } }
and the following JSON
{ "options":{ "foo":{} } }
Expected Results:
Generated at https://www.jsonschemavalidator.net/
Actual Results:
Code used to validate and show errors reported:
result, err := gojsonschema.Validate(schemaLoader, requestLoader) if !result.Valid() { for _, err := range result.Errors() { log.Println() } }
Actual Error Message:
options: Must validate at least one schema (anyOf)
layers: one is required
The text was updated successfully, but these errors were encountered: