Class: Interpol::RequestParamsParser::ParamValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/interpol/request_params_parser.rb

Overview

Private: This takes care of the validation.

Instance Method Summary collapse

Constructor Details

#initialize(endpoint_definition, configuration) ⇒ ParamValidator

Returns a new instance of ParamValidator.



39
40
41
42
43
# File 'lib/interpol/request_params_parser.rb', line 39

def initialize(endpoint_definition, configuration)
  @endpoint_definition = endpoint_definition
  @configuration = configuration
  @params_schema = build_params_schema
end

Instance Method Details

#param_definitionsObject



60
61
62
63
# File 'lib/interpol/request_params_parser.rb', line 60

def param_definitions
  @param_definitions ||= property_defs_from(:path_params).merge \
    property_defs_from(:query_params)
end

#validate!(params) ⇒ Object

Raises:



55
56
57
58
# File 'lib/interpol/request_params_parser.rb', line 55

def validate!(params)
  errors = ::JSON::Validator.fully_validate(@params_schema, params, :version => :draft3)
  raise ValidationError.new(errors, params, description) if errors.any?
end

#validate_path_params_valid_for_route!Object



45
46
47
48
49
50
51
52
53
# File 'lib/interpol/request_params_parser.rb', line 45

def validate_path_params_valid_for_route!
  route = @endpoint_definition.route
  invalid_params = property_defs_from(:path_params).keys.reject do |param|
    route =~ %r</:#{Regexp.escape(param)}(/|$)>
  end

  return if invalid_params.none?
  raise InvalidPathParamsError.new(*invalid_params)
end