fix fragment when used with extended schema #323
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.
This refactors some of
Validator
to fix an issue with validating afragment 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 anissue because if the root of the schema declares a
$schema
, thatinformation 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 constructorentirely. 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 theschema_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.