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