Skip to content

Commit a3233fa

Browse files
committed
allow overriding tag definitions
1 parent 79052e3 commit a3233fa

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ end
202202
* [token_owner](#token_owner)
203203
* [security_definitions](#security_definitions)
204204
* [models](#models)
205+
* [tags](#tags)
205206
* [hide_documentation_path](#hide_documentation_path)
206207
* [info](#info)
207208

@@ -329,6 +330,18 @@ add_swagger_documentation \
329330
]
330331
```
331332
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+
332345
<a name="hide_documentation_path" />
333346
#### hide_documentation_path: (default: `true`)
334347
```ruby

lib/grape-swagger/doc_methods.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ def setup(options)
5353

5454
paths, definitions = endpoint.path_and_definition_objects(combi_routes, options)
5555
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+
5663
output[:tags] = tags unless tags.empty? || paths.blank?
5764
output[:paths] = paths unless paths.blank?
5865
output[:definitions] = definitions unless definitions.blank?

spec/swagger_v2/default_api_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,28 @@ def app
132132
expect(subject['contact']['email']).to eql('[email protected]')
133133
end
134134
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
135159
end

0 commit comments

Comments
 (0)