Skip to content

Commit 1f19ca6

Browse files
committed
Allow exclusive refs into sibling definitions
I don't think this is really correct according to the [specification][0], but it matches the previous behavior and seems useful. Drafts after 7 don't have a problem because they allow all keywords as `$ref` siblings. Related: - #44 (comment) - json-schema-org/JSON-Schema-Test-Suite#458 [0]: https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-01#section-8.3
1 parent 410c3d7 commit 1f19ca6

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/json_schemer/schema.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ def parse
329329

330330
if value.key?('$ref') && keywords.fetch('$ref').exclusive?
331331
@parsed['$ref'] = keywords.fetch('$ref').new(value.fetch('$ref'), self, '$ref')
332+
defs_keyword = meta_schema.defs_keyword
333+
if value.key?(defs_keyword) && keywords.key?(defs_keyword)
334+
@parsed[defs_keyword] = keywords.fetch(defs_keyword).new(value.fetch(defs_keyword), self, defs_keyword)
335+
end
332336
else
333337
keyword_order = meta_schema.keyword_order
334338
last = keywords.size

test/ref_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,19 @@ def test_it_handles_relative_base_uri_json_pointer_ref
364364
assert(schema.valid?({ 'bar' => 1 }))
365365
refute(schema.valid?({ 'bar' => '1' }))
366366
end
367+
368+
def test_exclusive_ref_supports_definitions
369+
schema = JSONSchemer.schema({
370+
'$schema' => 'http://json-schema.org/draft-07/schema#',
371+
'$ref' => '#yah',
372+
'definitions' => {
373+
'yah' => {
374+
'$id' => '#yah',
375+
'type' => 'integer'
376+
}
377+
}
378+
})
379+
assert(schema.valid?(1))
380+
refute(schema.valid?('1'))
381+
end
367382
end

0 commit comments

Comments
 (0)