Skip to content
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

Make intra-doc refs work when validating with :fragment #127

Merged
merged 1 commit into from Oct 26, 2014

Conversation

mpalmer
Copy link
Contributor

@mpalmer mpalmer commented Sep 21, 2014

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.

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.
pd added a commit that referenced this pull request Oct 26, 2014
Make intra-doc refs work when validating with :fragment
@pd pd merged commit 94fafe6 into voxpupuli:master Oct 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants