Skip to content

Commit 404f96a

Browse files
committed
Ignore $id when $ref is present
I guess `$ref` isn't supposed to take sibling `$id` values into account. This switches to modifying the current `parent_uri` after `$ref` is processed. I still needed to update the root `parent_uri` to support `test_it_handles_nested_refs`, when the schema has an `$id` based on where it was fetched. Addresses failures from: json-schema-org/JSON-Schema-Test-Suite#493
1 parent e019baf commit 404f96a

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
@@ -122,13 +122,14 @@ def validate_instance(instance, &block)
122122
ref = schema['$ref']
123123
id = schema[id_keyword]
124124

125-
instance.parent_uri = join_uri(instance.parent_uri, id)
126-
127125
if ref
126+
instance.parent_uri ||= URI.parse(root[id_keyword]) if root.key?(id_keyword)
128127
validate_ref(instance, ref, &block)
129128
return
130129
end
131130

131+
instance.parent_uri = join_uri(instance.parent_uri, id)
132+
132133
if format? && custom_format?(format)
133134
validate_custom_format(instance, formats.fetch(format), &block)
134135
end

0 commit comments

Comments
 (0)