Class: Apicraft::Openapi::Response
- Inherits:
-
Object
- Object
- Apicraft::Openapi::Response
- Defined in:
- lib/apicraft/openapi/response.rb
Overview
Represents an OpenAPI response.
Instance Attribute Summary collapse
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #content ⇒ Object
- #content_for(content_type = nil) ⇒ Object
- #default_content_type ⇒ Object
- #description ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #mock(content_type = nil) ⇒ Object
- #schema_for(content_type = nil) ⇒ Object
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
#response ⇒ Object
Returns the value of attribute response.
7 8 9 |
# File 'lib/apicraft/openapi/response.rb', line 7 def response @response end |
Instance Method Details
#content ⇒ Object
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_type ⇒ Object
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 |
#description ⇒ Object
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 |