Skip to content

Commit e547555

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 9f5148a commit e547555

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
@@ -102,13 +102,14 @@ def validate_instance(instance, &block)
102102
ref = schema['$ref']
103103
id = schema[id_keyword]
104104

105-
instance.parent_uri = join_uri(instance.parent_uri, id)
106-
107105
if ref
106+
instance.parent_uri ||= URI.parse(root[id_keyword]) if root.key?(id_keyword)
108107
validate_ref(instance, ref, &block)
109108
return
110109
end
111110

111+
instance.parent_uri = join_uri(instance.parent_uri, id)
112+
112113
if format? && custom_format?(format)
113114
validate_custom_format(instance, formats.fetch(format), &block)
114115
end

0 commit comments

Comments
 (0)