Class: OpenapiContracts::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_contracts/parser.rb

Defined Under Namespace

Modules: Transformers

Constant Summary collapse

TRANSFORMERS =
[Transformers::Pointer].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rootfile) ⇒ Parser

Returns a new instance of Parser.



13
14
15
16
17
# File 'lib/openapi_contracts/parser.rb', line 13

def initialize(rootfile)
  @cwd = rootfile.parent
  @rootfile = rootfile
  @filenesting = {}
end

Instance Attribute Details

#filenestingObject (readonly)

Returns the value of attribute filenesting.



11
12
13
# File 'lib/openapi_contracts/parser.rb', line 11

def filenesting
  @filenesting
end

#rootfileObject (readonly)

Returns the value of attribute rootfile.



11
12
13
# File 'lib/openapi_contracts/parser.rb', line 11

def rootfile
  @rootfile
end

Class Method Details

.call(dir, filename) ⇒ Object



7
8
9
# File 'lib/openapi_contracts/parser.rb', line 7

def self.call(dir, filename)
  new(dir.join(filename)).parse
end

Instance Method Details

#parseObject



19
20
21
22
23
24
25
26
# File 'lib/openapi_contracts/parser.rb', line 19

def parse
  @filenesting = build_file_list
  @filenesting.each_with_object({}) do |(path, pointer), schema|
    target = pointer.to_a.reduce(schema) { |d, k| d[k] ||= {} }
    target.delete('$ref') # ref file pointers should be in the file list so save to delete
    target.merge! file_to_data(path, pointer)
  end
end