Sha256: dcef15a87b7fe2ce2e70f54b23bf5ab8c4a48b409325593d21e92c0df5539eec

Contents?: true

Size: 1.09 KB

Versions: 28

Compression:

Stored size: 1.09 KB

Contents

class OpenAPIParser::ParameterValidator
  class << self
    # @param [Hash{String => Parameter}] parameters_hash
    # @param [Hash] params
    # @param [String] object_reference
    # @param [OpenAPIParser::SchemaValidator::Options] options
    # @param [Boolean] is_header is header or not (ignore params key case)
    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

    private

    def convert_key(k, is_header)
      is_header ? k&.downcase : k
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
openapi_parser-2.2.2 lib/openapi_parser/parameter_validator.rb
openapi_parser-2.2.1 lib/openapi_parser/parameter_validator.rb
openapi_parser-2.2.0 lib/openapi_parser/parameter_validator.rb
openapi_parser-2.1.0 lib/openapi_parser/parameter_validator.rb
openapi_parser-2.0.0 lib/openapi_parser/parameter_validator.rb
openapi_parser_firetail-1.0.0 lib/openapi_parser/parameter_validator.rb
openapi_parser-1.0.0 lib/openapi_parser/parameter_validator.rb
openapi_parser-1.0.0.beta1 lib/openapi_parser/parameter_validator.rb
openapi_parser-0.15.0 lib/openapi_parser/parameter_validator.rb
openapi_parser-0.14.1 lib/openapi_parser/parameter_validator.rb
openapi_parser-0.14.0 lib/openapi_parser/parameter_validator.rb
openapi_parser-0.13.0 lib/openapi_parser/parameter_validator.rb
openapi_parser-0.12.1 lib/openapi_parser/parameter_validator.rb
openapi_parser-0.12.0 lib/openapi_parser/parameter_validator.rb
openapi_parser-0.11.2 lib/openapi_parser/parameter_validator.rb
openapi_parser-0.11.1 lib/openapi_parser/parameter_validator.rb
openapi_parser-0.11.0 lib/openapi_parser/parameter_validator.rb
openapi_parser-0.10.0 lib/openapi_parser/parameter_validator.rb
openapi_parser-0.9.0 lib/openapi_parser/parameter_validator.rb
openapi_parser-0.8.0 lib/openapi_parser/parameter_validator.rb