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, ignore_invalid_content_type: false, ignore_missing_path: false, schema: nil) ⇒ Validator
constructor
A new instance of Validator.
Constructor Details
#initialize(env: nil, ignore_invalid_content_type: false, ignore_missing_path: false, schema: nil) ⇒ Validator
Returns a new instance of Validator.
39 40 41 42 43 44 |
# File 'lib/rack/json_schema/request_validation.rb', line 39 def initialize(env: nil, ignore_invalid_content_type: false, ignore_missing_path: false, schema: nil) @env = env @ignore_invalid_content_type = ignore_invalid_content_type @ignore_missing_path = ignore_missing_path @schema = schema end |
Class Method Details
.call(**args) ⇒ Object
Utility wrapper method
31 32 33 |
# File 'lib/rack/json_schema/request_validation.rb', line 31 def self.call(**args) new(**args).call end |
Instance Method Details
#call ⇒ Object
Raises an error if any error detected
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rack/json_schema/request_validation.rb', line 48 def call if has_link_for_current_action? if has_body? && !has_valid_content_type? unless ignore_invalid_content_type? raise InvalidContentType end else case when content_type_json? && has_body? && !has_valid_json? raise InvalidJson when content_type_json? && has_schema? && !has_hash_request_body? raise InvalidParameter, "Invalid request. Request body must be an Object in JSON." when content_type_json? && has_schema? && !has_valid_parameter? raise InvalidParameter, "Invalid request.\n#{}" end end elsif !ignore_missing_path? raise LinkNotFound, "Could not find the link definition for request path #{path}." end end |