Class: Swagger::Api::Operations::Base
- Inherits:
-
Object
- Object
- Swagger::Api::Operations::Base
show all
- Includes:
- ActiveAttr::Model, Concerns::Columns
- Defined in:
- lib/swagger/api/operations/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
8
9
10
|
# File 'lib/swagger/api/operations/base.rb', line 8
def action
@action
end
|
#controller ⇒ Object
Returns the value of attribute controller.
8
9
10
|
# File 'lib/swagger/api/operations/base.rb', line 8
def controller
@controller
end
|
Instance Method Details
#create ⇒ Object
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/swagger/api/operations/base.rb', line 10
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/swagger/api/operations/base.rb', line 61
def error_responses
[
{
'404' => { '$ref' => '#/components/responses/NotFound' }
},
{
'401' => { '$ref' => '#/components/responses/Unauthorized' }
},
{
'422' => { '$ref' => '#/components/responses/BadRequest' }
},
{
'500' => { '$ref' => '#/components/responses/Unexpected' }
}
]
end
|
#model ⇒ Object
86
87
88
|
# File 'lib/swagger/api/operations/base.rb', line 86
def model
@model ||= model_name.constantize
end
|
#model_name ⇒ Object
82
83
84
|
# File 'lib/swagger/api/operations/base.rb', line 82
def model_name
@model_name ||= controller.model
end
|
#parameters ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/swagger/api/operations/base.rb', line 21
def parameters
[
{
name: 'id',
in: 'path',
description: "ID of #{model_name}",
required: true,
schema: {
type: :integer,
format: :int64,
minimum: 1
},
}
]
end
|
#readable_action ⇒ Object
78
79
80
|
# File 'lib/swagger/api/operations/base.rb', line 78
def readable_action
@readable_action ||= self.class.name.demodulize.downcase
end
|
#responses ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/swagger/api/operations/base.rb', line 37
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/swagger/api/operations/base.rb', line 46
def success_response
{
'200' => {
description: "#{readable_action} #{model_name.downcase}'s information",
content: {
'application/json; charset=utf-8' => {
schema: {
'$ref' => "#/components/schemas/#{model_name}"
}
}
}
}
}
end
|