Class: SwaggerApi::Operations::Base
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
10
11
12
|
# File 'lib/swagger_api/operations/base.rb', line 10
def action
@action
end
|
#controller ⇒ Object
Returns the value of attribute controller.
10
11
12
|
# File 'lib/swagger_api/operations/base.rb', line 10
def controller
@controller
end
|
Instance Method Details
#create ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'lib/swagger_api/operations/base.rb', line 12
def create
{
summary: "#{readable_action} #{model_name}",
description: "#{readable_action} #{model_name.downcase}'s information",
parameters: parameters,
responses: responses,
tags: [model_name]
}
end
|
#error_responses ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/swagger_api/operations/base.rb', line 66
def error_responses
[
{
'404' => { '$ref' => '#/components/responses/NotFound' }
},
{
'401' => { '$ref' => '#/components/responses/Unauthorized' }
},
{
'422' => { '$ref' => '#/components/responses/BadRequest' }
}
]
end
|
#model ⇒ Object
88
89
90
|
# File 'lib/swagger_api/operations/base.rb', line 88
def model
@model ||= model_name.constantize
end
|
#model_name ⇒ Object
84
85
86
|
# File 'lib/swagger_api/operations/base.rb', line 84
def model_name
@model_name ||= controller.model
end
|
#parameters ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/swagger_api/operations/base.rb', line 22
def parameters
[
{
name: 'id',
in: 'path',
description: "ID of #{model_name}",
required: true,
schema: {
type: :integer,
format: :int64,
minimum: 1
}
}
]
end
|
#readable_action ⇒ Object
80
81
82
|
# File 'lib/swagger_api/operations/base.rb', line 80
def readable_action
@readable_action ||= self.class.name.demodulize.downcase
end
|
#request_body ⇒ Object
38
39
40
41
42
|
# File 'lib/swagger_api/operations/base.rb', line 38
def request_body
{
'$ref' => "#/components/requestBodies/#{model_name}"
}
end
|
#responses ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/swagger_api/operations/base.rb', line 44
def responses
return @responses unless @responses.nil?
@responses = success_response
error_responses.each do |error_response|
@responses.merge!(error_response)
end
@responses
end
|
#success_response ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/swagger_api/operations/base.rb', line 53
def success_response
{
'200' => {
description: "#{readable_action} #{model_name.downcase}'s information",
content: {
'application/json; charset=utf-8' => {
schema: schema(model)
}
}
}
}
end
|