-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
Load local copy of draft schemas #362
Conversation
This sounds like a minor change but it's necessary in order to clear the schema cache between tests in the common test suite. |
begin | ||
validator = self.class.validator_for_uri(schema_uri) | ||
schema_uri = JSON::Util::URI.file_uri(validator.metaschema) | ||
rescue JSON::Schema::SchemaError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this using exceptions for control flow (aka bad habit)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes... That is exactly right. I tried to avoid refactoring the other method. Perhaps it should take an option, so that it can return nil if it finds nothing? (Or, even better, I could replace validator_for with two methods - validator_for and validator_for! - and have the first method return nil and the second throw an exception?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've already tried to clean up validator_for in #346 - perhaps I should take it further?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing that would also help resolve #254
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having a bang and a non-bang method as you suggest is a good idea. And it should be easy to do as validator_for_uri
itself explicitly checks for nil
and if found raises the exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've corrected that now, by allowing validator_for_uri
to take a second parameter that allows it to return nil
(rather than raising an exception).
I chose that implementation (rather than bang methods) so that we don't change the default behaviour of any methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!
If you refer to a draft schema in a $ref (as the common test suite does) json-schema will load it from json-schema.org even though the gem contains a local copy. This change patches JSON::Validator#load_ref_schema to check whether a $ref refers to a draft schema before trying to load from the web, and if so parsing and serving up the local copy. I've also replaced the local copy of draft3 with the exact version found online (only whitespace was different).
b4278ff
to
cdaed9d
Compare
If you refer to a draft schema in a $ref (as the common test suite does)
json-schema will load it from json-schema.org even though the gem
contains a local copy.
This change patches JSON::Validator#load_ref_schema to check whether a
$ref refers to a draft schema before trying to load from the web, and if
so parsing and serving up the local copy.
I've also replaced the local copy of draft3 with the exact version found
online (only whitespace was different).