Class: Committee::SchemaValidator::HyperSchema::RequestValidator
- Inherits:
-
Object
- Object
- Committee::SchemaValidator::HyperSchema::RequestValidator
- Defined in:
- lib/committee/schema_validator/hyper_schema/request_validator.rb
Instance Method Summary collapse
- #call(request, params, headers) ⇒ Object
-
#initialize(link, options = {}) ⇒ RequestValidator
constructor
A new instance of RequestValidator.
Constructor Details
#initialize(link, options = {}) ⇒ RequestValidator
Returns a new instance of RequestValidator.
7 8 9 10 11 |
# File 'lib/committee/schema_validator/hyper_schema/request_validator.rb', line 7 def initialize(link, = {}) @link = link @check_content_type = .fetch(:check_content_type, true) @check_header = .fetch(:check_header, true) end |
Instance Method Details
#call(request, params, headers) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/committee/schema_validator/hyper_schema/request_validator.rb', line 13 def call(request, params, headers) check_content_type!(request, params) if @check_content_type if @link.schema valid, errors = @link.schema.validate(params) if !valid errors = JsonSchema::SchemaError.aggregate(errors).join("\n") raise InvalidRequest, "Invalid request.\n\n#{errors}" end end if @check_header && @link.respond_to?(:header_schema) && @link.header_schema valid, errors = @link.header_schema.validate(headers) if !valid errors = JsonSchema::SchemaError.aggregate(errors).join("\n") raise InvalidRequest, "Invalid request.\n\n#{errors}" end end end |