Class: OpenapiFirst::ErrorResponses::JsonApi
Instance Attribute Summary
#env, #request_validation_error
Instance Method Summary
collapse
#data, #initialize, #message, #render, #schema, #validation_output
Instance Method Details
#body ⇒ Object
8
9
10
|
# File 'lib/openapi_first/error_responses/json_api.rb', line 8
def body
MultiJson.dump({ errors: serialized_errors })
end
|
#content_type ⇒ Object
12
13
14
|
# File 'lib/openapi_first/error_responses/json_api.rb', line 12
def content_type
'application/vnd.api+json'
end
|
#default_errors ⇒ Object
33
34
35
36
37
38
|
# File 'lib/openapi_first/error_responses/json_api.rb', line 33
def default_errors
[{
status: status.to_s,
title: message
}]
end
|
#pointer(data_pointer) ⇒ Object
51
52
53
54
55
|
# File 'lib/openapi_first/error_responses/json_api.rb', line 51
def pointer(data_pointer)
return data_pointer if location == :body
data_pointer.delete_prefix('/')
end
|
#pointer_key ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/openapi_first/error_responses/json_api.rb', line 40
def pointer_key
case location
when :body
:pointer
when :query, :path
:parameter
else
location
end
end
|
#serialized_errors ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/openapi_first/error_responses/json_api.rb', line 16
def serialized_errors
return default_errors unless validation_output
key = pointer_key
validation_errors&.map do |error|
{
status: status.to_s,
source: { key => pointer(error['instanceLocation']) },
title: error['error']
}
end
end
|
#validation_errors ⇒ Object
29
30
31
|
# File 'lib/openapi_first/error_responses/json_api.rb', line 29
def validation_errors
validation_output['errors'] || [validation_output]
end
|