Class: OpenapiFirst::Validators::ResponseHeaders

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ ResponseHeaders

Returns a new instance of ResponseHeaders.



13
14
15
# File 'lib/openapi_first/validators/response_headers.rb', line 13

def initialize(schema)
  @schema = schema
end

Instance Attribute Details

#schemaObject (readonly)

Returns the value of attribute schema.



17
18
19
# File 'lib/openapi_first/validators/response_headers.rb', line 17

def schema
  @schema
end

Class Method Details

.for(response_definition, openapi_version:) ⇒ Object



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

def self.for(response_definition, openapi_version:)
  schema = response_definition&.headers_schema
  return unless schema

  new(Schema.new(schema, openapi_version:))
end

Instance Method Details

#call(parsed_request) ⇒ Object



19
20
21
22
# File 'lib/openapi_first/validators/response_headers.rb', line 19

def call(parsed_request)
  validation = schema.validate(parsed_request.headers)
  Failure.fail!(:invalid_response_header, errors: validation.errors) if validation.error?
end