Class: Interpol::RequestParamsParser::ParamValidator
- Inherits:
-
Object
- Object
- Interpol::RequestParamsParser::ParamValidator
- Defined in:
- lib/interpol/request_params_parser.rb
Overview
Private: This takes care of the validation.
Instance Method Summary collapse
-
#initialize(endpoint_definition, configuration) ⇒ ParamValidator
constructor
A new instance of ParamValidator.
- #param_definitions ⇒ Object
- #validate!(params) ⇒ Object
- #validate_path_params_valid_for_route! ⇒ Object
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_definitions ⇒ Object
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
55 56 57 58 |
# File 'lib/interpol/request_params_parser.rb', line 55 def validate!(params) errors = ::JSON::Validator.fully_validate(@params_schema, params) 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 |