Class: OpenapiFirst::Response

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

Overview

Represents a response definition in the OpenAPI document. This is not a direct reflecton of the OpenAPI 3.X response definition, but a combination of status, content type and content schema.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, headers:, content_type:, content_schema:, openapi_version:) ⇒ Response

Returns a new instance of Response.



12
13
14
15
16
17
18
19
20
# File 'lib/openapi_first/response.rb', line 12

def initialize(status:, headers:, content_type:, content_schema:, openapi_version:)
  @status = status
  @content_type = content_type
  @content_schema = content_schema
  @headers = headers
  @headers_schema = build_headers_schema(headers)
  @parser = ResponseParser.new(headers:, content_type:)
  @validator = ResponseValidator.new(self, openapi_version:)
end

Instance Attribute Details

#content_schemaObject (readonly)



25
26
27
# File 'lib/openapi_first/response.rb', line 25

def content_schema
  @content_schema
end

#content_typeObject (readonly)



25
26
27
# File 'lib/openapi_first/response.rb', line 25

def content_type
  @content_type
end

#headersObject (readonly)



25
26
27
# File 'lib/openapi_first/response.rb', line 25

def headers
  @headers
end

#headers_schemaObject (readonly)



25
26
27
# File 'lib/openapi_first/response.rb', line 25

def headers_schema
  @headers_schema
end

#statusObject (readonly)



25
26
27
# File 'lib/openapi_first/response.rb', line 25

def status
  @status
end

Instance Method Details

#validate(response) ⇒ Object



27
28
29
30
31
# File 'lib/openapi_first/response.rb', line 27

def validate(response)
  parsed_values = @parser.parse(response)
  error = @validator.call(parsed_values)
  ValidatedResponse.new(response, parsed_values:, error:, response_definition: self)
end