brandur / json_schema

A JSON Schema V4 and Hyperschema V4 parser and validator.
MIT License
230 stars 45 forks source link

Provide better type error messages #31

Closed gjtorikian closed 9 years ago

gjtorikian commented 9 years ago

Currently, when a validation fails to match one or more types, an error message like the following is returned:

[{\"hello\"=>{\"content\"=>\"bar\"}}] is not a object/null.

This PR suggests that we transforms the "a object/null" portion into something a little friendlier:

[{\"hello\"=>{\"content\"=>\"bar\"}}] is not an object or null.

For multiple errors, the output would be:

[{\"hello\"=>{\"content\"=>\"bar\"}}] is not an object, null, or integer.

The code is more or less the same way Rails does it.

/cc @izuzak @jasonrudolph since we'd been discussing this internally.

brandur commented 9 years ago

@gjtorikian Love it! Thank-you.

In the general spirit of leaving things better than they were before, what do you think about adding some basic unit tests for the formatter (one word, two words, three words)?

gjtorikian commented 9 years ago

@brandur Done!

brandur commented 9 years ago

Thanks!

brandur commented 9 years ago

Released as 0.7.0.