Class: OpenapiFirst::ErrorResponse

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

Overview

This is the base class for error responses

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, request_validation_error) ⇒ ErrorResponse

Returns a new instance of ErrorResponse.

Parameters:



8
9
10
11
# File 'lib/openapi_first/error_response.rb', line 8

def initialize(env, request_validation_error)
  @env = env
  @request_validation_error = request_validation_error
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



15
16
17
# File 'lib/openapi_first/error_response.rb', line 15

def env
  @env
end

#request_validation_errorObject (readonly)

Returns the value of attribute request_validation_error.



15
16
17
# File 'lib/openapi_first/error_response.rb', line 15

def request_validation_error
  @request_validation_error
end

Instance Method Details

#bodyObject

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/openapi_first/error_response.rb', line 41

def body
  raise NotImplementedError
end

#content_typeObject



39
# File 'lib/openapi_first/error_response.rb', line 39

def content_type = 'application/json'

#dataObject



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

def data
  schema_validation&.data
end

#messageObject



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

def message
  request_validation_error.message
end

#renderObject



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

def render
  Rack::Response.new(body, status, Rack::CONTENT_TYPE => content_type).finish
end

#schemaObject



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

def schema
  schema_validation&.schema
end

#validation_outputObject



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

def validation_output
  schema_validation&.output
end