Class: Committee::SchemaValidator::OpenAPI3::ResponseValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/committee/schema_validator/open_api_3/response_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation_wrapper, validator_option) ⇒ ResponseValidator

Returns a new instance of ResponseValidator.

Parameters:



11
12
13
14
15
16
17
# File 'lib/committee/schema_validator/open_api_3/response_validator.rb', line 11

def initialize(operation_wrapper, validator_option)
  @operation_wrapper = operation_wrapper
  @validate_success_only = validator_option.validate_success_only
  @check_header = validator_option.check_header
  @allow_empty_date_and_datetime = validator_option.allow_empty_date_and_datetime
  @coerce_response_values = validator_option.coerce_response_values
end

Instance Attribute Details

#validate_success_onlyObject (readonly)

Returns the value of attribute validate_success_only.



7
8
9
# File 'lib/committee/schema_validator/open_api_3/response_validator.rb', line 7

def validate_success_only
  @validate_success_only
end

Instance Method Details

#call(status, headers, response_data, strict) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/committee/schema_validator/open_api_3/response_validator.rb', line 19

def call(status, headers, response_data, strict)
  return unless validate?(status)

  validator_options = { allow_empty_date_and_datetime: @allow_empty_date_and_datetime, coerce_value: @coerce_response_values }

  operation_wrapper.validate_response_params(status, headers, response_data, strict, check_header, validator_options: validator_options)
end

#validate?(status) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/committee/schema_validator/open_api_3/response_validator.rb', line 27

def validate?(status)
  case status
  when 204
    false
  when 200..299
    true
  when 304
    false
  else
    !validate_success_only
  end
end