Class: OpenapiFirst::RuntimeResponse
- Inherits:
-
Object
- Object
- OpenapiFirst::RuntimeResponse
- Extended by:
- Forwardable
- Defined in:
- lib/openapi_first/runtime_response.rb
Instance Method Summary collapse
- #body ⇒ Object
- #description ⇒ Object
- #headers ⇒ Object
-
#initialize(operation, rack_response) ⇒ RuntimeResponse
constructor
A new instance of RuntimeResponse.
- #known? ⇒ Boolean
- #known_status? ⇒ Boolean
- #response_definition ⇒ Object
- #validate ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(operation, rack_response) ⇒ RuntimeResponse
Returns a new instance of RuntimeResponse.
11 12 13 14 |
# File 'lib/openapi_first/runtime_response.rb', line 11 def initialize(operation, rack_response) @operation = operation @rack_response = rack_response end |
Instance Method Details
#body ⇒ Object
31 32 33 |
# File 'lib/openapi_first/runtime_response.rb', line 31 def body @body ||= content_type =~ /json/i ? load_json(original_body) : original_body end |
#description ⇒ Object
27 28 29 |
# File 'lib/openapi_first/runtime_response.rb', line 27 def description response_definition&.description end |
#headers ⇒ Object
35 36 37 |
# File 'lib/openapi_first/runtime_response.rb', line 35 def headers @headers ||= unpack_response_headers end |
#known? ⇒ Boolean
19 20 21 |
# File 'lib/openapi_first/runtime_response.rb', line 19 def known? !!response_definition end |
#known_status? ⇒ Boolean
23 24 25 |
# File 'lib/openapi_first/runtime_response.rb', line 23 def known_status? @operation.response_status_defined?(status) end |
#response_definition ⇒ Object
48 49 50 |
# File 'lib/openapi_first/runtime_response.rb', line 48 def response_definition @response_definition ||= @operation.response_for(status, content_type) end |
#validate ⇒ Object
39 40 41 |
# File 'lib/openapi_first/runtime_response.rb', line 39 def validate ResponseValidation::Validator.new(@operation).validate(self) end |
#validate! ⇒ Object
43 44 45 46 |
# File 'lib/openapi_first/runtime_response.rb', line 43 def validate! error = validate error&.raise! end |