Class: OpenapiFirst::RequestValidation
- Inherits:
-
Object
- Object
- OpenapiFirst::RequestValidation
- Includes:
- UseRouter
- Defined in:
- lib/openapi_first/request_validation.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Method Summary collapse
-
#call(env) ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#initialize(app, options = {}) ⇒ RequestValidation
constructor
A new instance of RequestValidation.
Constructor Details
#initialize(app, options = {}) ⇒ RequestValidation
Returns a new instance of RequestValidation.
13 14 15 16 |
# File 'lib/openapi_first/request_validation.rb', line 13 def initialize(app, = {}) @app = app @raise = .fetch(:raise_error, false) end |
Instance Method Details
#call(env) ⇒ Object
rubocop:disable Metrics/AbcSize
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/openapi_first/request_validation.rb', line 18 def call(env) # rubocop:disable Metrics/AbcSize operation = env[OPERATION] return @app.call(env) unless operation env[INBOX] = {} catch(:halt) do validate_query_parameters!(env, operation, env[PARAMETERS]) req = Rack::Request.new(env) content_type = req.content_type return @app.call(env) unless operation.request_body validate_request_content_type!(content_type, operation) body = req.body.read req.body.rewind parse_and_validate_request_body!(env, content_type, body, operation) @app.call(env) end end |