File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Expand file tree Collapse file tree 3 files changed +44
-0
lines changed 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 @@ -53,6 +53,13 @@ def setup(options)
53
53
54
54
paths , definitions = endpoint . path_and_definition_objects ( combi_routes , options )
55
55
tags = GrapeSwagger ::DocMethods ::TagNameDescription . build ( paths )
56
+
57
+ if options [ :tags ]
58
+ names = options [ :tags ] . map { |t | t [ :name ] }
59
+ tags . reject! { |t | names . include? ( t [ :name ] ) }
60
+ tags += options [ :tags ]
61
+ end
62
+
56
63
output [ :tags ] = tags unless tags . empty? || paths . blank?
57
64
output [ :paths ] = paths unless paths . blank?
58
65
output [ :definitions ] = definitions unless definitions . blank?
Original file line number Diff line number Diff line change @@ -132,4 +132,28 @@ def app
132
132
expect ( subject [ 'contact' ] [ 'email' ] ) . to eql ( '[email protected] ' )
133
133
end
134
134
end
135
+
136
+ context 'with tags' do
137
+ def app
138
+ Class . new ( Grape ::API ) do
139
+ format :json
140
+ desc 'This gets something.'
141
+ get '/something' do
142
+ { bla : 'something' }
143
+ end
144
+ add_swagger_documentation tags : [
145
+ { name : 'something' , description : 'customized description' }
146
+ ]
147
+ end
148
+ end
149
+
150
+ subject do
151
+ get '/swagger_doc'
152
+ JSON . parse ( last_response . body )
153
+ end
154
+
155
+ it 'documents the customized tag' do
156
+ expect ( subject [ 'tags' ] ) . to eql ( [ { 'name' => 'something' , 'description' => 'customized description' } ] )
157
+ end
158
+ end
135
159
end
You can’t perform that action at this time.
0 commit comments