Class: OpenAPIParser::ParameterValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_parser/parameter_validator.rb

Class Method Summary collapse

Class Method Details

.validate_parameter(parameters_hash, params, object_reference, options, is_header = false) ⇒ Object

Parameters:

  • parameters_hash (Hash{String => Parameter})
  • params (Hash)
  • object_reference (String)
  • options (OpenAPIParser::SchemaValidator::Options)
  • is_header (Boolean) (defaults to: false)

    is header or not (ignore params key case)

Raises:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/openapi_parser/parameter_validator.rb', line 8

def validate_parameter(parameters_hash, params, object_reference, options, is_header = false)
  no_exist_required_key = []

  params_key_converted = params.keys.map { |k| [convert_key(k, is_header), k] }.to_h
  parameters_hash.each do |k, v|
    key = params_key_converted[convert_key(k, is_header)]
    if params.include?(key)
      coerced = v.validate_params(params[key], options)
      params[key] = coerced if options.coerce_value
    elsif v.required
      no_exist_required_key << k
    end
  end

  raise OpenAPIParser::NotExistRequiredKey.new(no_exist_required_key, object_reference) unless no_exist_required_key.empty?

  params
end