Class: OpenapiFirst::Validators::ResponseBody
- Inherits:
-
Object
- Object
- OpenapiFirst::Validators::ResponseBody
- Defined in:
- lib/openapi_first/validators/response_body.rb
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Class Method Summary collapse
Instance Method Summary collapse
- #call(response) ⇒ Object
-
#initialize(schema) ⇒ ResponseBody
constructor
A new instance of ResponseBody.
Constructor Details
#initialize(schema) ⇒ ResponseBody
Returns a new instance of ResponseBody.
13 14 15 |
# File 'lib/openapi_first/validators/response_body.rb', line 13 def initialize(schema) @schema = schema end |
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
17 18 19 |
# File 'lib/openapi_first/validators/response_body.rb', line 17 def schema @schema end |
Class Method Details
.for(response_definition, openapi_version:) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/openapi_first/validators/response_body.rb', line 6 def self.for(response_definition, openapi_version:) schema = response_definition&.content_schema return unless schema new(Schema.new(schema, write: false, openapi_version:)) end |
Instance Method Details
#call(response) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/openapi_first/validators/response_body.rb', line 19 def call(response) begin parsed_body = response.body rescue ParseError => e Failure.fail!(:invalid_response_body, message: e.) end validation = schema.validate(parsed_body) Failure.fail!(:invalid_response_body, errors: validation.errors) if validation.error? end |