Class: SwaggerModel::SwaggerV2::Attributes
- Inherits:
-
Object
- Object
- SwaggerModel::SwaggerV2::Attributes
- Defined in:
- lib/swagger_model/attributes.rb
Instance Method Summary collapse
-
#initialize(hash, model_name, suffix = 'Attributes') ⇒ Attributes
constructor
A new instance of Attributes.
- #to_swagger_hash(model) ⇒ Object
Constructor Details
#initialize(hash, model_name, suffix = 'Attributes') ⇒ Attributes
Returns a new instance of Attributes.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/swagger_model/attributes.rb', line 6 def initialize(hash, model_name, suffix='Attributes') @attributes = [] @suffix = suffix @model_name = model_name hash.keys.each do |key| value = hash[key] attribute = get_attribute(value, key) @attributes.push(attribute) end end |
Instance Method Details
#to_swagger_hash(model) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/swagger_model/attributes.rb', line 17 def to_swagger_hash(model) hash = { 'type' => 'object' } properties = {} @attributes.each do |e| attribute = get_attribute_swagger(e, model) properties[e['key']] = attribute end hash['properties'] = properties hash['required'] = properties.keys name = @model_name + @suffix model[name] = hash { '$ref' => "#/definitions/#{name}" } end |