Class: OpenapiFirst::ResponseValidation
- Inherits:
-
Object
- Object
- OpenapiFirst::ResponseValidation
- Includes:
- UseRouter
- Defined in:
- lib/openapi_first/response_validation.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, _options = {}) ⇒ ResponseValidation
constructor
A new instance of ResponseValidation.
- #validate(response, operation) ⇒ Object
Constructor Details
#initialize(app, _options = {}) ⇒ ResponseValidation
Returns a new instance of ResponseValidation.
11 12 13 |
# File 'lib/openapi_first/response_validation.rb', line 11 def initialize(app, = {}) @app = app end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/openapi_first/response_validation.rb', line 15 def call(env) operation = env[OPERATION] return @app.call(env) unless operation response = @app.call(env) validate(response, operation) response end |
#validate(response, operation) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/openapi_first/response_validation.rb', line 24 def validate(response, operation) status, headers, body = response.to_a return validate_status_only(operation, status) if status == 204 content_type = headers[Rack::CONTENT_TYPE] response_schema = operation.response_schema_for(status, content_type) validate_response_body(response_schema, body) if response_schema end |