Class: SoberSwag::Reporting::Compiler::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/sober_swag/reporting/compiler.rb

Overview

Compile component schemas.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSchema

Returns a new instance of Schema.



7
8
9
10
# File 'lib/sober_swag/reporting/compiler.rb', line 7

def initialize
  @references = {}
  @referenced_schemas = Set.new
end

Instance Attribute Details

#referencesObject (readonly)

Hash of references to type definitions. Suitable for us as the components hash.



15
16
17
# File 'lib/sober_swag/reporting/compiler.rb', line 15

def references
  @references
end

Instance Method Details

#compile(value) ⇒ Object



17
18
19
# File 'lib/sober_swag/reporting/compiler.rb', line 17

def compile(value)
  compile_inner(value.swagger_schema)
end

#compile_inner(value) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/sober_swag/reporting/compiler.rb', line 21

def compile_inner(value)
  initial, found = value

  merge_found(found)

  initial
end

#merge_found(found) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/sober_swag/reporting/compiler.rb', line 29

def merge_found(found)
  found.each do |k, v|
    next unless @referenced_schemas.add?(k)

    @references[k] = compile_inner(v.call)
  end
end