From aedee7379d466a6128353c0fb594f2c21d68b9d8 Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Fri, 1 Mar 2019 15:47:21 -0700 Subject: [PATCH] Rearrange nested schema expansion This is simply to make it easier to see the change in the next commit, which addresses an edge case in the nested expansion. --- lib/json_schema/reference_expander.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/json_schema/reference_expander.rb b/lib/json_schema/reference_expander.rb index f239297..5b06954 100644 --- a/lib/json_schema/reference_expander.rb +++ b/lib/json_schema/reference_expander.rb @@ -110,21 +110,23 @@ def dereference(ref_schema, ref_stack) # references. if ref.uri schema_children(new_schema) do |subschema| - next if subschema.expanded? - next unless subschema.reference - # Don't bother if the subschema points to the same # schema as the reference schema. next if ref_schema == subschema - if !subschema.reference.uri - # the subschema's ref is local to the file that the - # subschema is in; however since there's no URI - # the 'resolve_pointer' method would try to look it up - # within @schema. So: manually reconstruct the reference to - # use the URI of the parent ref. - subschema.reference = JsonReference::Reference.new("#{ref.uri}#{subschema.reference.pointer}") + next if subschema.expanded? + + if subschema.reference + if !subschema.reference.uri + # the subschema's ref is local to the file that the + # subschema is in; however since there's no URI + # the 'resolve_pointer' method would try to look it up + # within @schema. So: manually reconstruct the reference to + # use the URI of the parent ref. + subschema.reference = JsonReference::Reference.new("#{ref.uri}#{subschema.reference.pointer}") + end end + dereference(subschema, ref_stack) end end