Class: OpenapiFirst::ErrorResponses::Default
Overview
Instance Attribute Summary
#failure
Instance Method Summary
collapse
#initialize, #render, #status
Instance Method Details
#body ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/openapi_first/error_responses/default.rb', line 23
def body
result = {
title:,
status:
}
result[:errors] = errors if failure.errors
MultiJson.dump(result)
end
|
#content_type ⇒ Object
38
39
40
|
# File 'lib/openapi_first/error_responses/default.rb', line 38
def content_type
'application/problem+json'
end
|
#errors ⇒ Object
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/openapi_first/error_responses/default.rb', line 42
def errors
key = pointer_key
failure.errors.map do |error|
{
message: error.message,
key => pointer(error.data_pointer),
code: error.type
}
end
end
|
#pointer(data_pointer) ⇒ Object
66
67
68
69
70
|
# File 'lib/openapi_first/error_responses/default.rb', line 66
def pointer(data_pointer)
return data_pointer if type == :invalid_body
data_pointer.delete_prefix('/')
end
|
#pointer_key ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/openapi_first/error_responses/default.rb', line 53
def pointer_key
case type
when :invalid_body
:pointer
when :invalid_query, :invalid_path
:parameter
when :invalid_header
:header
when :invalid_cookie
:cookie
end
end
|
#title ⇒ Object
34
35
36
|
# File 'lib/openapi_first/error_responses/default.rb', line 34
def title
TITLES.fetch(type)
end
|
#type ⇒ Object
32
|
# File 'lib/openapi_first/error_responses/default.rb', line 32
def type = failure.type
|