Class: OpenapiFirst::Validators::ResponseHeaders

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_first/validators/response_headers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headers) ⇒ ResponseHeaders

Returns a new instance of ResponseHeaders.



6
7
8
# File 'lib/openapi_first/validators/response_headers.rb', line 6

def initialize(headers)
  @headers = headers
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



10
11
12
# File 'lib/openapi_first/validators/response_headers.rb', line 10

def headers
  @headers
end

Instance Method Details

#call(parsed_response) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/openapi_first/validators/response_headers.rb', line 12

def call(parsed_response)
  headers.each do |header|
    header_value = parsed_response.headers[header.name]
    next if header_value.nil? && !header.required?

    validation_errors = header.schema.validate(header_value)
    next unless validation_errors.any?

    Failure.fail!(:invalid_response_header,
                  errors: [error_for(data_pointer: "/#{header.name}", value: header_value,
                                     error: validation_errors.first)])
  end
end