lib/fakeit/validation/validator.rb in fakeit-0.1.4 vs lib/fakeit/validation/validator.rb in fakeit-0.1.5
- old
+ new
@@ -5,28 +5,26 @@
@operation = operation
end
def validate(body: '', params: {}, headers: {})
options = OpenAPIParser::SchemaValidator::Options.new(coerce_value: true)
- body_data = parse(body)
- @operation.validate_request_body(request_content_type, body_data) if need_validate?(body_data)
+ if request_content_type
+ body_data = parse(body)
+ @operation.validate_request_body(request_content_type, body_data)
+ end
@operation.validate_path_params(options)
@operation.validate_request_parameter(params, headers, options)
rescue StandardError => e
raise ValidationError, e.message
end
private
- def need_validate?(body_data)
- request_content_type && body_data
- end
-
def parse(body)
JSON.parse(body)
rescue StandardError
- nil
+ raise ValidationError, 'Invalid json payload'
end
def request_content_type
request_body&.content&.find { |k, _| k =~ %r{^application/.*json} }&.first
end