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.



56
57
58
# File 'lib/swaggard/swagger/response.rb', line 56

def id
  @id
end

#response_classObject

Returns the value of attribute response_class.



56
57
58
# File 'lib/swaggard/swagger/response.rb', line 56

def response_class
  @response_class
end

Instance Method Details

#parse(value) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/swaggard/swagger/response.rb', line 58

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



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

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

#to_docObject



67
68
69
70
71
72
73
74
75
76
# File 'lib/swaggard/swagger/response.rb', line 67

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