Class: Swaggard::Swagger::Response::ResponseModel

Inherits:
Object
  • Object
show all
Defined in:
lib/swaggard/swagger/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject

Returns the value of attribute id.



77
78
79
# File 'lib/swaggard/swagger/response.rb', line 77

def id
  @id
end

#response_classObject

Returns the value of attribute response_class.



77
78
79
# File 'lib/swaggard/swagger/response.rb', line 77

def response_class
  @response_class
end

Instance Method Details

#parse(value) ⇒ Object



79
80
81
82
83
84
85
86
# File 'lib/swaggard/swagger/response.rb', line 79

def parse(value)
  @is_array_response = value =~ /Array/
  @response_class = if @is_array_response
                      value.match(/^Array<(.*)>$/)[1]
                    else
                      value
                    end
end

#response_class_typeObject



99
100
101
102
103
104
105
# File 'lib/swaggard/swagger/response.rb', line 99

def response_class_type
  if PRIMITIVE_TYPES.include?(@response_class)
    { 'type' => @response_class }
  else
    { '$ref' => "#/definitions/#@response_class" }
  end
end

#to_docObject



88
89
90
91
92
93
94
95
96
97
# File 'lib/swaggard/swagger/response.rb', line 88

def to_doc
  if @is_array_response
    {
      'type'  => 'array',
      'items' => response_class_type
    }
  else
    response_class_type
  end
end