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:



10
11
12
13
# File 'lib/openapi_first/error_response.rb', line 10

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.



17
18
19
# File 'lib/openapi_first/error_response.rb', line 17

def env
  @env
end

#request_validation_errorObject (readonly)

Returns the value of attribute request_validation_error.



17
18
19
# File 'lib/openapi_first/error_response.rb', line 17

def request_validation_error
  @request_validation_error
end

Instance Method Details

#bodyObject

Raises:

  • (NotImplementedError)


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

def body
  raise NotImplementedError
end

#content_typeObject



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

def content_type = 'application/json'

#dataObject



29
30
31
# File 'lib/openapi_first/error_response.rb', line 29

def data
  schema_validation&.data
end

#messageObject



33
34
35
# File 'lib/openapi_first/error_response.rb', line 33

def message
  request_validation_error.message
end

#renderObject



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

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

#schemaObject



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

def schema
  schema_validation&.schema
end

#validation_outputObject



21
22
23
# File 'lib/openapi_first/error_response.rb', line 21

def validation_output
  schema_validation&.output
end