Skip to content

Commit a760c44

Browse files
committed
add hax to deref json nodes that point into the document's schemas property
1 parent 47760f3 commit a760c44

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/scorpio/json/node.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,25 @@ def deref
6060
return self.class.new_by_type(document, Hana::Pointer.parse(match.post_match)).deref
6161
end
6262

63+
# HAX for how google does refs and ids
64+
if document_node['schemas'].respond_to?(:to_hash)
65+
if document_node['schemas'][content['$ref']]
66+
return document_node['schemas'][content['$ref']]
67+
end
68+
_, deref_by_id = document_node['schemas'].detect { |_k, schema| schema['id'] == content['$ref'] }
69+
if deref_by_id
70+
return deref_by_id
71+
end
72+
end
73+
6374
#raise(NotImplementedError, "cannot dereference #{content['$ref']}") # TODO
6475
return self
6576
end
6677

78+
def document_node
79+
Node.new_by_type(document, [])
80+
end
81+
6782
ESC = {'^' => '^^', '~' => '~0', '/' => '~1'} # '/' => '^/' ?
6883
def pointer_path
6984
path.map { |part| "/" + part.to_s.gsub(/[\^~\/]/) { |m| ESC[m] } }.join('')

0 commit comments

Comments
 (0)