Class: OpenapiFirst::RequestValidation
- Inherits:
-
Object
- Object
- OpenapiFirst::RequestValidation
- Includes:
- UseRouter
- Defined in:
- lib/openapi_first/request_validation.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ RequestValidation
constructor
A new instance of RequestValidation.
Constructor Details
#initialize(app, options = {}) ⇒ RequestValidation
Returns a new instance of RequestValidation.
15 16 17 18 19 20 |
# File 'lib/openapi_first/request_validation.rb', line 15 def initialize(app, = {}) @app = app @raise = .fetch(:raise_error, false) @error_response_class = Plugins.find_error_response(.fetch(:error_response, Config..error_response)) end |
Instance Method Details
#call(env) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/openapi_first/request_validation.rb', line 22 def call(env) operation = env[OPERATION] return @app.call(env) unless operation error = validate_request(operation, env) if error location, title = error.values_at(:location, :title) raise RequestInvalidError, (title, location) if @raise return error_response(error).render end @app.call(env) end |