Class: OpenapiFirst::DefaultErrorResponse
Instance Attribute Summary
#data, #location, #schema, #status, #title, #validation_output
Instance Method Summary
collapse
#content_type, #initialize, #render
Instance Method Details
#body ⇒ Object
7
8
9
|
# File 'lib/openapi_first/default_error_response.rb', line 7
def body
MultiJson.dump({ errors: serialized_errors })
end
|
#default_errors ⇒ Object
23
24
25
26
27
28
|
# File 'lib/openapi_first/default_error_response.rb', line 23
def default_errors
[{
status: status.to_s,
title:
}]
end
|
#pointer(data_pointer) ⇒ Object
41
42
43
44
45
|
# File 'lib/openapi_first/default_error_response.rb', line 41
def pointer(data_pointer)
return data_pointer if location == :request_body
data_pointer.delete_prefix('/')
end
|
#pointer_key ⇒ Object
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/openapi_first/default_error_response.rb', line 30
def pointer_key
case location
when :request_body
:pointer
when :query, :path
:parameter
else
location
end
end
|
#serialized_errors ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/openapi_first/default_error_response.rb', line 11
def serialized_errors
return default_errors unless validation_output
key = pointer_key
[
{
source: { key => pointer(validation_output['instanceLocation']) },
title: validation_output['error']
}
]
end
|