Class: SwaggerModel::SwaggerV2::Model
- Inherits:
-
Object
- Object
- SwaggerModel::SwaggerV2::Model
- Defined in:
- lib/swagger_model/model.rb
Instance Method Summary collapse
-
#initialize(hash) ⇒ Model
constructor
A new instance of Model.
- #to_swagger_hash(model) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Model
Returns a new instance of Model.
7 8 9 10 11 12 13 14 15 |
# File 'lib/swagger_model/model.rb', line 7 def initialize(hash) @id = hash['id'] @type = hash['type'] @model_name = ActiveSupport::Inflector.classify(@type.gsub('-', '_')) @attributes = Attributes.new(hash['attributes'], @model_name) if !hash['relationships'].nil? @relationships = Relationships.new(hash['relationships']) 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 34 35 36 37 38 39 40 |
# File 'lib/swagger_model/model.rb', line 17 def to_swagger_hash(model) model[@model_name] = {} aModel = model[@model_name] hash = { 'type' => 'object', 'properties' => { 'id' => { 'type' => 'string', 'example' => @id }, 'type' => { 'type' => 'string', 'example' => @type }, 'attributes' => @attributes.to_swagger_hash(aModel) } } hash['properties']['relationships'] = @relationships.to_swagger_hash(aModel, @model_name) unless @relationships.nil? aModel[@model_name] = hash { '$ref' => "#/definitions/#{@model_name}" } end |