Open enicholson opened 10 years ago
Unfortunately the schema itself does not get validated.
The original thinking was that schemas would be valid/tested so validating the schema itself would not be worth the performance hit. But JaySchema strives for correctness, even at the expense of speed, and it’s obviously not cool to throw
there. So that may have to change (or have automatic schema validation be an option in a future version).
In the meantime, you can do something like this to validate the schema before validating the instance:
js.validate(schema, 'http://json-schema.org/draft-04/schema#');
(The draft-04
schema is built-in so this does not have to go out and load it from somewhere.)
Thanks Nate. I'll add in calls to validate like you mentioned.
Would it make sense to add some generic error handling around the validation method in Jayschema so the callback could at least be invoked with something like "Unexpected error"?
Cheers!
On Wed, Oct 1, 2014 at 1:45 AM, Nate Silva notifications@github.com wrote:
Unfortunately the schema itself does not get validated.
The original thinking was that schemas would be valid/tested so validating the schema itself would not be worth the performance hit. But JaySchema strives for correctness, even at the expense of speed, and it’s obviously not cool to throw there. So that may have to change (or have automatic schema validation be an option in a future version).
In the meantime, you can do something like this to validate the schema before validating the instance:
js.validate(schema, 'http://json-schema.org/draft-04/schema#');
(The draft-04 schema is built-in so this does not have to go out and load it from somewhere.)
— Reply to this email directly or view it on GitHub https://github.com/natesilva/jayschema/issues/43#issuecomment-57421613.
I ran into a case where an invalid schema was used that had an enum property with the array undefined. JaySchema didn't throw an exception or invoke the callback.
Here's a quick example to illustrate the problem:
With 0.3.1 I get a stack trace on the console, but with 0.2.7 I didn't get anything at all (so at least that's an improvement).