Class: GoaModelGen::SwaggerLoader
Instance Attribute Summary
Attributes inherited from BaseLoader
#fields_key, #kind, #path, #raw, #types_key
Instance Method Summary
collapse
Methods inherited from BaseLoader
#build_field
Constructor Details
Returns a new instance of SwaggerLoader.
56
57
58
|
# File 'lib/goa_model_gen/loader.rb', line 56
def initialize(path)
super(path, SwaggerDef, 'definitions', 'properties')
end
|
Instance Method Details
#build_type(name, d) ⇒ Object
60
61
62
63
64
65
66
67
|
# File 'lib/goa_model_gen/loader.rb', line 60
def build_type(name, d)
super(name, d).tap do |r|
required_fields = d['required']
r.fields.each do |f|
f.required = (required_fields || []).include?(f.name)
end
end
end
|
#dig(path) ⇒ Object
88
89
90
|
# File 'lib/goa_model_gen/loader.rb', line 88
def dig(path)
dig_into(raw, path.split('/'), [])
end
|
#dig_into(hash, keys, footprints) ⇒ Object
92
93
94
95
96
97
98
99
|
# File 'lib/goa_model_gen/loader.rb', line 92
def dig_into(hash, keys, )
key = keys.shift
value = hash[key]
return value if keys.empty?
raise "No data for #{key} in #{.join('/')}" if value.nil?
return dig_into(value, keys, + [key])
end
|
#load(name) ⇒ Object
73
74
75
76
77
78
79
80
|
# File 'lib/goa_model_gen/loader.rb', line 73
def load(name)
d = lookup(name)
unless d
GoaModelGen.logger.info("#{name} not found in #{path}")
return nil
end
build_type(name, d)
end
|
#load!(name) ⇒ Object
82
83
84
85
86
|
# File 'lib/goa_model_gen/loader.rb', line 82
def load!(name)
r = load(name)
raise "#{name} not found in #{path}" unless r
r
end
|
#lookup(name) ⇒ Object
69
70
71
|
# File 'lib/goa_model_gen/loader.rb', line 69
def lookup(name)
raw[types_key][name]
end
|