Class: OpenapiFirst::Validators::RequestParameters
- Inherits:
-
Object
- Object
- OpenapiFirst::Validators::RequestParameters
- Defined in:
- lib/openapi_first/validators/request_parameters.rb
Constant Summary collapse
- RequestHeaders =
Data.define(:schema) do def call(parsed_values) validation = schema.validate(parsed_values[:headers]) Failure.fail!(:invalid_header, errors: validation.errors) if validation.error? end end
- Path =
Data.define(:schema) do def call(parsed_values) validation = schema.validate(parsed_values[:path]) Failure.fail!(:invalid_path, errors: validation.errors) if validation.error? end end
- Query =
Data.define(:schema) do def call(parsed_values) validation = schema.validate(parsed_values[:query]) Failure.fail!(:invalid_query, errors: validation.errors) if validation.error? end end
- RequestCookies =
Data.define(:schema) do def call(parsed_values) validation = schema.validate(parsed_values[:cookies]) Failure.fail!(:invalid_cookie, errors: validation.errors) if validation.error? end end
- VALIDATORS =
{ path_schema: Path, query_schema: Query, header_schema: RequestHeaders, cookie_schema: RequestCookies }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #call(parsed_values) ⇒ Object
-
#initialize(validators) ⇒ RequestParameters
constructor
A new instance of RequestParameters.
Constructor Details
#initialize(validators) ⇒ RequestParameters
Returns a new instance of RequestParameters.
52 53 54 |
# File 'lib/openapi_first/validators/request_parameters.rb', line 52 def initialize(validators) @validators = validators end |
Class Method Details
.for(operation, openapi_version:, hooks: {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/openapi_first/validators/request_parameters.rb', line 41 def self.for(operation, openapi_version:, hooks: {}) after_property_validation = hooks[:after_request_parameter_property_validation] validators = VALIDATORS.filter_map do |key, klass| schema = operation.send(key) klass.new(Schema.new(schema, after_property_validation:, openapi_version:)) if schema end return if validators.empty? new(validators) end |
Instance Method Details
#call(parsed_values) ⇒ Object
56 57 58 |
# File 'lib/openapi_first/validators/request_parameters.rb', line 56 def call(parsed_values) @validators.each { |validator| validator.call(parsed_values) } end |