Fix regression resolving $ref with sibling definitions - #102
Merged
Merged
Conversation
The $ref resolution clause rebuilt the node as %{"$ref" => ref},
discarding every sibling key including "definitions". Any pointer into
a sibling "definitions" (e.g. #/definitions/foo alongside a $ref) then
failed to resolve and raised InvalidReferenceError, a regression from
v0.10.2.
Resolve the full schema instead, while keeping the clause ahead of the
$id/id clauses so a sibling $id still does not change the base URI (per
draft 4/6/7 semantics). Sibling validation keywords remain ignored at
validation time in Validator.validation_errors/4.
Fixes #101
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #101 — a regression between v0.10.2 and v0.11.x where resolving a schema whose node contains both
$refand siblingdefinitionsraisedInvalidReferenceError.The
$refresolution clause inExJsonSchema.Schemarebuilt the node as%{"$ref" => ref}, discarding every sibling key — includingdefinitions. As a result any pointer into a siblingdefinitions(e.g.#/definitions/fooalongside a$ref) could no longer be resolved:Changes
$refnode instead of stripping siblings, sodefinitions(and other structural keys) survive resolution.$refclause ahead of the$id/idclauses so a sibling$idstill does not change the base URI, preserving draft 4/6/7 semantics ($ref prevents a sibling $id from changing the base uriin the official suite).Validator.validation_errors/4, so draft 4/6/7 "$ref overrides siblings" behavior is unchanged.Tests
schema_test.exs: resolving a$refto a sibling definition succeeds.validator_test.exs: validation via a$refwith a sibling definition (root and nested) reports the correct error.Test plan
mix testMade with Cursor