Class: JsonRefs::Dereferencer

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_first/json_refs.rb

Instance Method Summary collapse

Constructor Details

#initialize(doc_dir, doc, file_cache) ⇒ Dereferencer

Returns a new instance of Dereferencer.



70
71
72
73
74
# File 'lib/openapi_first/json_refs.rb', line 70

def initialize(doc_dir, doc, file_cache)
  @doc = doc
  @doc_dir = doc_dir
  @file_cache = file_cache
end

Instance Method Details

#call(doc = @doc, keys = []) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/openapi_first/json_refs.rb', line 76

def call(doc = @doc, keys = [])
  if doc.is_a?(Array)
    doc.each_with_index do |value, idx|
      call(value, keys + [idx])
    end
  elsif doc.is_a?(Hash)
    if doc.key?('$ref')
      dereference(keys, doc['$ref'])
    else
      doc.each do |key, value|
        call(value, keys + [key])
      end
    end
  end
  doc
end