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

Should be able to override the generated nicknames #100

Merged
merged 1 commit into from
Jul 17, 2014
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
@@ -1,5 +1,6 @@
### Next Release

* [#100](https://github.com/tim-vandecasteele/grape-swagger/pull/100): Added ability to specify a nickname for an endpoint - [@lhorne](https://github.com/lhorne).
* [#94](https://github.com/tim-vandecasteele/grape-swagger/pull/94): Added support for namespace descriptions - [@renier](https://github.com/renier).
* [#110](https://github.com/tim-vandecasteele/grape-swagger/pull/110), [#111](https://github.com/tim-vandecasteele/grape-swagger/pull/111) - Added `responseModel` support - [@bagilevi](https://github.com/bagilevi).
* [#105](https://github.com/tim-vandecasteele/grape-swagger/pull/105): Fixed compatibility with Swagger-UI - [@CraigCottingham](https://github.com/CraigCottingham).
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ desc 'Hide this endpoint', {
}
```


# Overriding auto generated nickname for an endpoint

You can specify a swagger nickname to use instead of the auto generated name by adding ```:nickname => 'string'``` in the description of the endpoint.

``` ruby
desc 'get a full list of Pets', {
:nickname => 'getAllPets'
}
```


## Grape Entities

Add the [grape-entity](https://github.com/agileanimal/grape-entity) gem to our Gemfile.
Expand Down
1 change: 1 addition & 0 deletions lib/grape-swagger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def self.setup(options)
end
end

operation[:nickname] = route.route_nickname if route.route_nickname
operation
end.compact
apis << {
Expand Down
22 changes: 22 additions & 0 deletions spec/non_default_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -590,4 +590,26 @@ def app
expect(subject['description']).to eql('Description for aspace')
end
end

context 'override nickname' do
before :all do
class NicknameAPI < Grape::API
desc 'This gets something.', nickname: 'getSomething'
get '/something' do
{ bla: 'something' }
end
add_swagger_documentation
end
end

def app
NicknameAPI
end

it 'documents the user-specified nickname' do
get '/swagger_doc/something.json'
ret = JSON.parse(last_response.body)
ret['apis'][0]['operations'][0]['nickname'].should == 'getSomething'
end
end
end