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

fix fragment when used with extended schema #323

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dpatti
Copy link
Contributor

@dpatti dpatti commented Apr 15, 2016

This refactors some of Validator to fix an issue with validating a
fragment of an extended schema against a json object. The problem is
that while navigating through the schema, we are using the configured
:version option as the validator for each partial schema. This is an
issue because if the root of the schema declares a $schema, that
information is lost in the traversal.

The refactor does two things. Firstly, it does not write back into
@options[:version] and it stops using it outside of the constructor
entirely. The only place that should know about this is the initialized
schema, and from that point on, the canonical validator should be the
schema object's validator since it makes a decision about which to use
in its constructor. So we can reduce complexity by using that validator
in the :validate_schema option branch.

The other place that used :version is the schema_from_fragment
method, which is where the bug exists. What we're doing here, instead of
dealing with schemas and hashes during the iterator, is pulling the
schema object out, digging through it using the fragments, and then
wrapping the result in a schema using the base_schema's validator.

Tests have been included that demonstrate the problem.

This refactors some of `Validator` to fix an issue with validating a
fragment of an extended schema against a json object. The problem is
that while navigating through the schema, we are using the configured
`:version` option as the validator for each partial schema. This is an
issue because if the root of the schema declares a `$schema`, that
information is lost in the traversal.

The refactor does two things. Firstly, it does not write back into
`@options[:version]` and it stops using it outside of the constructor
entirely. The only place that should know about this is the initialized
schema, and from that point on, the canonical validator should be the
schema object's validator since it makes a decision about which to use
in its constructor. Now we can reduce complexity by using that validator
in the `:validate_schema` option branch.

The other place that used `:version` is the `schema_from_fragment`
method, which is where the bug exists. What we're doing here, instead of
dealing with schemas *and* hashes during the iterator, is pulling the
schema object out, digging through it using the fragments, and then
wrapping the result in a schema using the `base_schema`'s validator.

Tests have been included that demonstrate the problem.
@iainbeeston
Copy link
Contributor

So what you're saying is that if we validate against a fragment, we should use the version from the base schema. That makes sense. However, I think your test is invalid - I think odd-a should have type: "object"?

@dpatti
Copy link
Contributor Author

dpatti commented Jun 27, 2016

I don't know if type: "object" is specifically necessary, and the other tests in the file do not have it. I am happy to add it if you think it is important. As it stands now, the test should fall without the patch and passes with it.

@iainbeeston
Copy link
Contributor

iainbeeston commented Jun 27, 2016 via email

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.

2 participants