Skip to content

Commit da1fb55

Browse files
pbenderskykzaitsev
authored andcommitted
added support for nicknamed routes (ruby-grape#483)
* added support for nicknamed routes * uses let instead of method to instantiate the app * updated spec to use anon class * fixed rubocop errors * Refactor to fix rubocop issues. * Added entry in Changelog.
1 parent dc2e25b commit da1fb55

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* [#476](https://github.com/ruby-grape/grape-swagger/pull/476): Fixes for handling the parameter type when body parameters are defined inside desc block - [@anakinj](https://github.com/anakinj).
1010
* [#478](https://github.com/ruby-grape/grape-swagger/pull/478): Refactors building of properties, corrects documentation of array items - [@LeFnord](https://github.com/LeFnord).
1111
* [#479](https://github.com/ruby-grape/grape-swagger/pull/479): Fix regex for Array and Multi Type in doc_methods. Parsing of "[APoint]" should return "APoint" - [@frodrigo](https://github.com/frodrigo).
12+
* [#483](https://github.com/ruby-grape/grape-swagger/pull/483): Added support for nicknamed routes - [@pbendersky](https://github.com/pbendersky)
1213
* Your contribution here.
1314

1415
### 0.22.0 (July 12, 2016)

lib/grape-swagger/doc_methods/operation_id.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ module DocMethods
33
class OperationId
44
class << self
55
def build(route, path = nil)
6-
verb = route.request_method.to_s.downcase
6+
if route.options[:nickname]
7+
operation_id = route.options[:nickname]
8+
else
9+
verb = route.request_method.to_s.downcase
710

8-
operation = manipulate(path) unless path.nil?
11+
operation = manipulate(path) unless path.nil?
912

10-
"#{verb}#{operation}"
13+
operation_id = "#{verb}#{operation}"
14+
end
15+
16+
operation_id
1117
end
1218

1319
def manipulate(path)

spec/swagger_v2/nicknamed_api_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'spec_helper'
2+
3+
describe 'a nicknamed mounted api' do
4+
def app
5+
Class.new(Grape::API) do
6+
desc 'Show this endpoint', nickname: 'simple'
7+
get '/simple' do
8+
{ foo: 'bar' }
9+
end
10+
11+
add_swagger_documentation format: :json
12+
end
13+
end
14+
15+
subject do
16+
get '/swagger_doc.json'
17+
JSON.parse(last_response.body)
18+
end
19+
20+
it 'uses the nickname as the operationId' do
21+
expect(subject['paths']['/simple']['get']['operationId']).to eql('simple')
22+
end
23+
end

0 commit comments

Comments
 (0)