Class: OpenapiFirst::JsonRefs::Dereferencer

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

Instance Method Summary collapse

Constructor Details

#initialize(filename, doc_dir, doc, file_cache) ⇒ Dereferencer

Returns a new instance of Dereferencer.



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

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

Instance Method Details

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



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

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