Class: Apicraft::Openapi::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/apicraft/openapi/response.rb

Overview

Represents an OpenAPI response.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



9
10
11
# File 'lib/apicraft/openapi/response.rb', line 9

def initialize(response)
  @response = response
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



7
8
9
# File 'lib/apicraft/openapi/response.rb', line 7

def response
  @response
end

Instance Method Details

#contentObject



23
24
25
# File 'lib/apicraft/openapi/response.rb', line 23

def content
  response.content
end

#content_for(content_type = nil) ⇒ Object



27
28
29
30
31
# File 'lib/apicraft/openapi/response.rb', line 27

def content_for(content_type = nil)
  return if content.blank?

  content[content_type || default_content_type]
end

#default_content_typeObject



17
18
19
20
21
# File 'lib/apicraft/openapi/response.rb', line 17

def default_content_type
  return if content.blank?

  content.keys[0]
end

#descriptionObject



13
14
15
# File 'lib/apicraft/openapi/response.rb', line 13

def description
  response.description
end

#mock(content_type = nil) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/apicraft/openapi/response.rb', line 37

def mock(content_type = nil)
  [
    Mocker.mock(
      schema_for(content_type || default_content_type)
    ),
    content_type || default_content_type
  ]
end

#schema_for(content_type = nil) ⇒ Object



33
34
35
# File 'lib/apicraft/openapi/response.rb', line 33

def schema_for(content_type = nil)
  content_for(content_type || default_content_type)&.schema
end