Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for nicknamed routes #483

Merged
merged 6 commits into from
Jul 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a period ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in #485

* Your contribution here.

### 0.22.0 (July 12, 2016)
Expand Down
12 changes: 9 additions & 3 deletions lib/grape-swagger/doc_methods/operation_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions spec/swagger_v2/nicknamed_api_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'spec_helper'

describe 'a nicknamed mounted api' do
def app
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use let!(:app) do instead method definition

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