Make intra-doc refs work when validating with :fragment #127
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Here's a weird corner-case for you: when calling JSON::Validator.validate
and using the :fragment option, any references to other parts of the same
schema would fail. Why? Because the handling of :fragment involved
creating a new schema, with a new URI, with a subset of the original
schema. Internal refs (as handled by JSON::Schema::RefAttribute) would try
to resolve the ref within this sub-schema, and go fwackoom because the
structure of the sub-schema wouldn't have the right path in it.
I've adjusted the code for schema_from_fragment to not call
initialize_schema (and hence not create those new sub-schemas), and instead
just create a new JSON::Schema object (which, according to the comments, is
the only reason that initialize_schema was being called). This causes no
new schemas to be created, and RefAttribute can go looking up its ref in the
right place.