diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e5907e1..df6496e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * [#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). * [#478](https://github.com/ruby-grape/grape-swagger/pull/478): Refactors building of properties, corrects documentation of array items - [@LeFnord](https://github.com/LeFnord). * [#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). +* [#483](https://github.com/ruby-grape/grape-swagger/pull/483): Added support for nicknamed routes - [@pbendersky](https://github.com/pbendersky) * Your contribution here. ### 0.22.0 (July 12, 2016) diff --git a/lib/grape-swagger/doc_methods/operation_id.rb b/lib/grape-swagger/doc_methods/operation_id.rb index a1872a8b..0134ca4d 100644 --- a/lib/grape-swagger/doc_methods/operation_id.rb +++ b/lib/grape-swagger/doc_methods/operation_id.rb @@ -3,11 +3,17 @@ module DocMethods class OperationId class << self def build(route, path = nil) - verb = route.request_method.to_s.downcase + if route.options[:nickname] + operation_id = route.options[:nickname] + else + verb = route.request_method.to_s.downcase - operation = manipulate(path) unless path.nil? + operation = manipulate(path) unless path.nil? - "#{verb}#{operation}" + operation_id = "#{verb}#{operation}" + end + + operation_id end def manipulate(path) diff --git a/spec/swagger_v2/nicknamed_api_spec.rb b/spec/swagger_v2/nicknamed_api_spec.rb new file mode 100644 index 00000000..f46185a9 --- /dev/null +++ b/spec/swagger_v2/nicknamed_api_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe 'a nicknamed mounted api' do + def app + Class.new(Grape::API) do + desc 'Show this endpoint', nickname: 'simple' + get '/simple' do + { foo: 'bar' } + end + + add_swagger_documentation format: :json + end + end + + subject do + get '/swagger_doc.json' + JSON.parse(last_response.body) + end + + it 'uses the nickname as the operationId' do + expect(subject['paths']['/simple']['get']['operationId']).to eql('simple') + end +end