tdegrunt / jsonschema

JSON Schema validation
Other
1.83k stars 263 forks source link

Error messages when validating nested schemas using oneOf #309

Closed hicksjduk closed 4 years ago

hicksjduk commented 4 years ago

This might be already covered by another issue, but I can't tell from the descriptions.

When I specify that a property is oneOf two nested schemas (referenced by $ref), if it doesn't match either schema then the validation fails correctly, but the only message issues says that it doesn't match exactly one of the schemas. This is correct, but to be helpful the errors raised when validating the nested schemas should also be included.

See https://github.com/hicksjduk/jsonschema for a test case showing this.

awwright commented 4 years ago

@hicksjduk Can you suggest a better message? Maybe something like

Instance does not match any of the schemas, exactly one is required

hicksjduk commented 4 years ago

The existing message is fine, but that wasn't what I was talking about. What I said was that the messages from the validation of the subschemas should also be included.

awwright commented 4 years ago

@hicksjduk How well does the "nestedErrors" option work for you?

hicksjduk commented 4 years ago

What is the "nestedErrors" option? Where is it documented? How is it used?

awwright commented 4 years ago

@hasansaghir It's described in a (somewhat short) passage in the README. You set it to true, and the output will include the errors will produced within. They are normally suppressed because it would also be an error to fix all of them.

How about you play around with it, see what the output looks like, and let me know how you think the README.md can be improved.

hicksjduk commented 4 years ago

The nestedErrors option does exactly what I want, thanks.

The main thing that is missing from the README is how to set the option: I had to look in the code to find out. It would also be good to have something which lists all the supported options. And thenestedErrors option should be referenced from the examples which show how to use anyOf, allOf or oneOf.

awwright commented 4 years ago

I'll spin that into a paragraph and add an example then.

awwright commented 4 years ago

Added an example and rewrote some of the text in 320464812ed401500dcae231b13c998f32dbe957. Please let me know how you think that works.

hicksjduk commented 4 years ago

Thanks Austin, that looks great. Thank you for your help with this.