Class: OpenapiFirst::ValidatedResponse

Inherits:
SimpleDelegator
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/openapi_first/validated_response.rb

Overview

A validated response. It can be valid or not.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_response, error:, parsed_values: nil, response_definition: nil) ⇒ ValidatedResponse

Returns a new instance of ValidatedResponse.



11
12
13
14
15
16
# File 'lib/openapi_first/validated_response.rb', line 11

def initialize(original_response, error:, parsed_values: nil, response_definition: nil)
  super(original_response)
  @error = error
  @parsed_values = parsed_values
  @response_definition = response_definition
end

Instance Attribute Details

#errorFailure? (readonly)

A Failure object if the response is invalid

Returns:



20
21
22
# File 'lib/openapi_first/validated_response.rb', line 20

def error
  @error
end

#response_definitionResponse? (readonly)

The response definition if this response is defined in the API description

Returns:



24
25
26
# File 'lib/openapi_first/validated_response.rb', line 24

def response_definition
  @response_definition
end

Instance Method Details

#invalid?Boolean

Checks if the response is invalid.

Returns:

  • (Boolean)


49
50
51
# File 'lib/openapi_first/validated_response.rb', line 49

def invalid?
  !valid?
end

#known?Boolean

Returns true if the response is defined.

Returns:

  • (Boolean)


45
# File 'lib/openapi_first/validated_response.rb', line 45

def known? = response_definition != nil

#parsed_bodyHash<String,anything>?

The parsed body

Returns:

  • (Hash<String,anything>, nil)


34
35
36
# File 'lib/openapi_first/validated_response.rb', line 34

def parsed_body
  @parsed_values&.body
end

#parsed_headersHash<String,anything>?

The parsed headers

Returns:

  • (Hash<String,anything>, nil)


28
29
30
# File 'lib/openapi_first/validated_response.rb', line 28

def parsed_headers
  @parsed_values&.headers
end

#valid?Boolean

Checks if the response is valid.

Returns:

  • (Boolean)

    true if the response is valid, false otherwise.



40
41
42
# File 'lib/openapi_first/validated_response.rb', line 40

def valid?
  error.nil?
end