Class: OpenapiFirst::RequestValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_first/request_validator.rb

Overview

Validates a Request against a request definition.

Constant Summary collapse

VALIDATORS =
[
  Validators::RequestParameters,
  Validators::RequestBody
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(request_definition, openapi_version:, hooks: {}) ⇒ RequestValidator

Returns a new instance of RequestValidator.



15
16
17
18
19
# File 'lib/openapi_first/request_validator.rb', line 15

def initialize(request_definition, openapi_version:, hooks: {})
  @validators = VALIDATORS.filter_map do |klass|
    klass.for(request_definition, hooks:, openapi_version:)
  end
end

Instance Method Details

#call(parsed_request) ⇒ Object



21
22
23
# File 'lib/openapi_first/request_validator.rb', line 21

def call(parsed_request)
  @validators.each { |v| v.call(parsed_request) }
end