Skip to content

Fix regression resolving $ref with sibling definitions - #102

Merged
jonasschmidt merged 2 commits into
masterfrom
fix/ref-sibling-definitions
Jul 9, 2026
Merged

jonasschmidt merged 2 commits into
masterfrom
fix/ref-sibling-definitions

Conversation

@jonasschmidt

Copy link
Copy Markdown
Owner

Summary

Fixes #101 — a regression between v0.10.2 and v0.11.x where resolving a schema whose node contains both $ref and sibling definitions raised InvalidReferenceError.

The $ref resolution clause in ExJsonSchema.Schema rebuilt the node as %{"$ref" => ref}, discarding every sibling key — including definitions. As a result any pointer into a sibling definitions (e.g. #/definitions/foo alongside a $ref) could no longer be resolved:

ExJsonSchema.Validator.validate(
  %{"$ref" => "#/definitions/foo", "definitions" => %{"foo" => %{"type" => "string"}}},
  5
)
# v0.11.4: ** (ExJsonSchema.Schema.InvalidReferenceError) invalid reference #/definitions/foo
# fixed:   {:error, [{"Type mismatch. Expected String but got Integer.", "#"}]}

Changes

  • Resolve the full schema for a $ref node instead of stripping siblings, so definitions (and other structural keys) survive resolution.
  • Keep the $ref clause ahead of the $id/id clauses so a sibling $id still does not change the base URI, preserving draft 4/6/7 semantics ($ref prevents a sibling $id from changing the base uri in the official suite).
  • Sibling validation keywords are still ignored at validation time via Validator.validation_errors/4, so draft 4/6/7 "$ref overrides siblings" behavior is unchanged.

Tests

  • schema_test.exs: resolving a $ref to a sibling definition succeeds.
  • validator_test.exs: validation via a $ref with a sibling definition (root and nested) reports the correct error.
  • Full suite (incl. draft 4/6/7 official test suites) passes: 3317 tests, 0 failures.

Test plan

  • mix test

Made with Cursor

jonasschmidt and others added 2 commits July 9, 2026 12:19
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>
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 91.806%. remained the same — fix/ref-sibling-definitions into master

@jonasschmidt
jonasschmidt merged commit d298fa9 into master Jul 9, 2026
7 of 11 checks passed
@jonasschmidt
jonasschmidt deleted the fix/ref-sibling-definitions branch July 9, 2026 15:10
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.

Regression with refs between v0.10.2 and v0.11.4

2 participants