-
-
Notifications
You must be signed in to change notification settings - Fork 243
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
JSON::Schema::Reader #175
JSON::Schema::Reader #175
Conversation
So the loader will be the single point through which we load any url, anywhere? (If so I'm all for it) |
02d08bb
to
32314c3
Compare
I think the remaining failures here are artifacts of the mixed use of URI and Addressable::URI, and would probably be solved by #174. I'll try merging that in (minus the no-file-URI rule stuff) and seeing what happens when I get a chance. |
26e2582
to
7bc7362
Compare
Just rebased this onto the new master after a lot of other changes around URI handling have landed; @RST-J's new tests for handling $ref with spaces in the names ended up exposing a bug in this branch! I'll try to come back and tidy this up soon, plus add some documentation. |
@RST-J @iainbeeston this is ready for review if you get time. |
end | ||
schema = JSON::Schema.new(schema,schema_uri,@options[:version]) | ||
Validator.add_schema(schema) | ||
rescue |
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.
This is kind of a side-note, but it'd be really good if we could catch specific errors here...
Sorry I didn't get a chance before, but this looks good. I like the idea of having a modular loader like this. My only comment is that I wonder if there should be a simpler API for users to set |
Conflicts: lib/json-schema/validator.rb
Prolly got some textile syntax a bit wrong, and the link to the yard docs won't work prior to this being merged.
I'll submit a separate PR to add pry (and pry-byebug) as dependencies in the Gemfile. Reverted some changes I made to attributes/ref.rb that would conflict with voxpupuli#186.
I'd be nervous about adding any further options to |
Does anyone else have any feedback on this PR? |
Very cool feature, this boosts performance more than we could with anything else at the moment I think. Plus it provides more security :-) |
So, do we want to rename Loader to something else before merging? |
Yeah, let me rename this first. I'm gonna go with Reader since it's basically spot on with how I described it's role: "read (as in I/O)". Not sure why it didn't occur to me before. =) I'll do that in the next couple of hours and ping you guys here when I'm done. |
Renamed |
The tests would catch it, right? 😉 |
👍 |
1 similar comment
👍 |
Introduced by conflicts in how voxpupuli#175 and voxpupuli#196 juggled webmock usage. Closes voxpupuli#207.
Adds a JSON::Schema::Reader object/interface that can be used to control how URLs/paths are fetched. The default behavior is the same as on master: unregistered schema references will be fetched used open-uri or File.read. The default implementation accepts initializer arguments that can be used to reject all URIs, all files, or as callbacks that will receive an
Addressable::URI
orPathname
object and should returntrue
orfalse
to indicate whether it should be requested.I've added documentation to the README explaining how to configure the reader, either by replacing the default instance used, or supplying a reader to use for a single call to
validate
.This addresses issues from #47, #65, #152, #173 / #174. Probably others. I didn't add any support for my
NullLoader
NullReader
idea mentioned in #152; since it's a simple interface to implement, users can just define their own which returns an empty schema (JSON::Schema.new({}, ...)
).