Class: OpenapiFirst::Response
- Inherits:
-
Object
- Object
- OpenapiFirst::Response
- Defined in:
- lib/openapi_first/response.rb
Overview
Represents a response definition in the OpenAPI document. This is not a direct reflecton of the OpenAPI 3.X response definition, but a combination of status, content type and content schema.
Instance Attribute Summary collapse
- #content_schema ⇒ Object readonly
- #content_type ⇒ Object readonly
- #headers ⇒ Object readonly
- #headers_schema ⇒ Object readonly
- #status ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(status:, headers:, content_type:, content_schema:, openapi_version:) ⇒ Response
constructor
A new instance of Response.
- #validate(response) ⇒ Object
Constructor Details
#initialize(status:, headers:, content_type:, content_schema:, openapi_version:) ⇒ Response
Returns a new instance of Response.
12 13 14 15 16 17 18 19 20 |
# File 'lib/openapi_first/response.rb', line 12 def initialize(status:, headers:, content_type:, content_schema:, openapi_version:) @status = status @content_type = content_type @content_schema = content_schema @headers = headers @headers_schema = build_headers_schema(headers) @parser = ResponseParser.new(headers:, content_type:) @validator = ResponseValidator.new(self, openapi_version:) end |
Instance Attribute Details
#content_schema ⇒ Object (readonly)
25 26 27 |
# File 'lib/openapi_first/response.rb', line 25 def content_schema @content_schema end |
#content_type ⇒ Object (readonly)
25 26 27 |
# File 'lib/openapi_first/response.rb', line 25 def content_type @content_type end |
#headers ⇒ Object (readonly)
25 26 27 |
# File 'lib/openapi_first/response.rb', line 25 def headers @headers end |
#headers_schema ⇒ Object (readonly)
25 26 27 |
# File 'lib/openapi_first/response.rb', line 25 def headers_schema @headers_schema end |
#status ⇒ Object (readonly)
25 26 27 |
# File 'lib/openapi_first/response.rb', line 25 def status @status end |
Instance Method Details
#validate(response) ⇒ Object
27 28 29 30 31 |
# File 'lib/openapi_first/response.rb', line 27 def validate(response) parsed_values = @parser.parse(response) error = @validator.call(parsed_values) ValidatedResponse.new(response, parsed_values:, error:, response_definition: self) end |