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)


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

def invalid?
  !valid?
end

#parsed_bodyHash<String,anything>

The parsed body

Returns:

  • (Hash<String,anything>)


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

def_delegator :@parsed_values, :body, :parsed_body

#parsed_headersHash<String,anything>

The parsed headers

Returns:

  • (Hash<String,anything>)


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

def_delegator :@parsed_values, :headers, :parsed_headers

#valid?Boolean

Checks if the response is valid.

Returns:

  • (Boolean)

    true if the response is valid, false otherwise.



38
39
40
# File 'lib/openapi_first/validated_response.rb', line 38

def valid?
  error.nil?
end