Class: OpenapiFirst::RuntimeResponse

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

Instance Method Summary collapse

Constructor Details

#initialize(operation, rack_response) ⇒ RuntimeResponse

Returns a new instance of RuntimeResponse.



11
12
13
14
# File 'lib/openapi_first/runtime_response.rb', line 11

def initialize(operation, rack_response)
  @operation = operation
  @rack_response = rack_response
end

Instance Method Details

#bodyObject



31
32
33
# File 'lib/openapi_first/runtime_response.rb', line 31

def body
  @body ||= content_type =~ /json/i ? load_json(original_body) : original_body
end

#descriptionObject



27
28
29
# File 'lib/openapi_first/runtime_response.rb', line 27

def description
  response_definition&.description
end

#headersObject



35
36
37
# File 'lib/openapi_first/runtime_response.rb', line 35

def headers
  @headers ||= unpack_response_headers
end

#known?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/openapi_first/runtime_response.rb', line 19

def known?
  !!response_definition
end

#known_status?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/openapi_first/runtime_response.rb', line 23

def known_status?
  @operation.response_status_defined?(status)
end

#response_definitionObject



48
49
50
# File 'lib/openapi_first/runtime_response.rb', line 48

def response_definition
  @response_definition ||= @operation.response_for(status, content_type)
end

#validateObject



39
40
41
# File 'lib/openapi_first/runtime_response.rb', line 39

def validate
  ResponseValidation::Validator.new(@operation).validate(self)
end

#validate!Object



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

def validate!
  error = validate
  error&.raise!
end