Class: Rack::JsonSchema::RequestValidation::Validator
- Inherits:
-
BaseRequestHandler
- Object
- BaseRequestHandler
- Rack::JsonSchema::RequestValidation::Validator
- Defined in:
- lib/rack/json_schema/request_validation.rb
Class Method Summary collapse
-
.call(**args) ⇒ Object
Utility wrapper method.
Instance Method Summary collapse
-
#call ⇒ Object
Raises an error if any error detected.
-
#initialize(env: nil, schema: nil, strict: nil) ⇒ Validator
constructor
A new instance of Validator.
Constructor Details
#initialize(env: nil, schema: nil, strict: nil) ⇒ Validator
Returns a new instance of Validator.
31 32 33 34 35 |
# File 'lib/rack/json_schema/request_validation.rb', line 31 def initialize(env: nil, schema: nil, strict: nil) @env = env @schema = schema @strict = strict end |
Class Method Details
.call(**args) ⇒ Object
Utility wrapper method
24 25 26 |
# File 'lib/rack/json_schema/request_validation.rb', line 24 def self.call(**args) new(**args).call end |
Instance Method Details
#call ⇒ Object
Raises an error if any error detected
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rack/json_schema/request_validation.rb', line 39 def call if has_link_for_current_action? if has_body? && !has_valid_content_type? if strict? raise InvalidContentType end else case when content_type_json? && has_body? && !has_valid_json? raise InvalidJson when content_type_json? && has_schema? && !has_valid_parameter? raise InvalidParameter, "Invalid request.\n#{}" end end elsif strict? raise LinkNotFound, "Could not find the link definition for request path #{path}." end end |