File tree 4 files changed +61
-1
lines changed 4 files changed +61
-1
lines changed Original file line number Diff line number Diff line change 4
4
5
5
* [ #583 ] ( https://github.com/ruby-grape/grape-swagger/pull/583 ) : Issue #582 : document file response - [ @LeFnord ] ( https://github.com/LeFnord ) .
6
6
* [ #588 ] ( https://github.com/ruby-grape/grape-swagger/pull/588 ) : Allow extension keys in Info object - [ @mattyr ] ( https://github.com/mattyr ) .
7
+ * [ #589 ] ( https://github.com/ruby-grape/grape-swagger/pull/589 ) : Allow overriding tag definitions in Info object - [ @mattyr ] ( https://github.com/mattyr ) .
7
8
8
9
* Your contribution here.
9
10
Original file line number Diff line number Diff line change 202
202
* [token_owner](# token_owner)
203
203
* [security_definitions](# security_definitions)
204
204
* [models](# models)
205
+ * [tags](# tags)
205
206
* [hide_documentation_path](# hide_documentation_path)
206
207
* [info](# info)
207
208
@@ -329,6 +330,18 @@ add_swagger_documentation \
329
330
]
330
331
```
331
332
333
+ <a name="tags" />
334
+ ### tags:
335
+ A list of tags to document. By default tags are automatically generated
336
+ for endpoints based on route names.
337
+
338
+ ```ruby
339
+ add_swagger_documentation \
340
+ tags: [
341
+ { name: ' widgets' , description: ' A description of widgets' }
342
+ ]
343
+ ```
344
+
332
345
<a name="hide_documentation_path" />
333
346
#### hide_documentation_path: (default: `true`)
334
347
```ruby
Original file line number Diff line number Diff line change @@ -52,7 +52,8 @@ def setup(options)
52
52
)
53
53
54
54
paths , definitions = endpoint . path_and_definition_objects ( combi_routes , options )
55
- tags = GrapeSwagger ::DocMethods ::TagNameDescription . build ( paths )
55
+ tags = tags_from ( paths , options )
56
+
56
57
output [ :tags ] = tags unless tags . empty? || paths . blank?
57
58
output [ :paths ] = paths unless paths . blank?
58
59
output [ :definitions ] = definitions unless definitions . blank?
@@ -109,5 +110,17 @@ def class_variables_from(options)
109
110
@@class_name = options [ :class_name ] || options [ :mount_path ] . delete ( '/' )
110
111
@@hide_documentation_path = options [ :hide_documentation_path ]
111
112
end
113
+
114
+ def tags_from ( paths , options )
115
+ tags = GrapeSwagger ::DocMethods ::TagNameDescription . build ( paths )
116
+
117
+ if options [ :tags ]
118
+ names = options [ :tags ] . map { |t | t [ :name ] }
119
+ tags . reject! { |t | names . include? ( t [ :name ] ) }
120
+ tags += options [ :tags ]
121
+ end
122
+
123
+ tags
124
+ end
112
125
end
113
126
end
Original file line number Diff line number Diff line change @@ -139,4 +139,37 @@ def app
139
139
expect ( subject [ 'x-logo' ] ) . to eql ( 'http://logo.com/img.png' )
140
140
end
141
141
end
142
+
143
+ context 'with tags' do
144
+ def app
145
+ Class . new ( Grape ::API ) do
146
+ format :json
147
+ desc 'This gets something.'
148
+ get '/something' do
149
+ { bla : 'something' }
150
+ end
151
+ get '/somethingelse' do
152
+ { bla : 'somethingelse' }
153
+ end
154
+
155
+ add_swagger_documentation tags : [
156
+ { name : 'something' , description : 'customized description' }
157
+ ]
158
+ end
159
+ end
160
+
161
+ subject do
162
+ get '/swagger_doc'
163
+ JSON . parse ( last_response . body )
164
+ end
165
+
166
+ it 'documents the customized tag' do
167
+ expect ( subject [ 'tags' ] ) . to eql (
168
+ [
169
+ { 'name' => 'somethingelse' , 'description' => 'Operations about somethingelses' } ,
170
+ { 'name' => 'something' , 'description' => 'customized description' }
171
+ ]
172
+ )
173
+ end
174
+ end
142
175
end
You can’t perform that action at this time.
0 commit comments