Skip to content

Commit 0b332dc

Browse files
committed
Evaluate ref pointers relative to parent
Previously, this was always evalutating pointers using the root schema. We actually want to evaluate them using the nearest parent schema with an `$id`, which we look up here using `parent_uri`. Addresses failures from: json-schema-org/JSON-Schema-Test-Suite#457
1 parent 47d04e1 commit 0b332dc

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/json_schemer/schema/base.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,11 @@ def validate_ref(instance, ref, &block)
311311
schema_pointer = ref.slice(1..-1)
312312
if valid_json_pointer?(schema_pointer)
313313
ref_pointer = Hana::Pointer.new(URI.decode_www_form_component(schema_pointer))
314+
ref_root = ids[instance.parent_uri.to_s]&.fetch(:schema) || root
314315
subinstance = instance.merge(
315-
schema: ref_pointer.eval(root),
316+
schema: ref_pointer.eval(ref_root),
316317
schema_pointer: schema_pointer,
317-
parent_uri: (pointer_uri(root, ref_pointer) || instance.parent_uri)
318+
parent_uri: (pointer_uri(ref_root, ref_pointer) || instance.parent_uri)
318319
)
319320
validate_instance(subinstance, &block)
320321
return

0 commit comments

Comments
 (0)