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

Prevent crashing when API has camelcase namespaces #321

Merged
merged 1 commit into from
Dec 26, 2015
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

* Your contribution here.

#### Fixes

* [#321](https://github.com/ruby-grape/grape-swagger/pull/321): Fixed handling paths containing uppercase letters - [@gekola](https://github.com/gekola).

### 0.10.4 (December 7, 2015)

* [#315](https://github.com/ruby-grape/grape-swagger/pull/315): Require `grape-entity` < 0.5.0 - [@dblock](https://github.com/dblock).
Expand Down
1 change: 0 additions & 1 deletion lib/grape-swagger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def add_swagger_documentation(options = {})
next unless route_match
resource = route_match.captures.first
next if resource.empty?
resource.downcase!
@target_class.combined_routes[resource] ||= []
next if documentation_class.hide_documentation_path && route.route_path.match(/#{documentation_class.mount_path}($|\/|\(\.)/)
@target_class.combined_routes[resource] << route
Expand Down
20 changes: 20 additions & 0 deletions spec/namespaced_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,24 @@ def app
expect(subject['description']).to eql('Description for aspace')
end
end

context 'with camelcase endpoints' do
def app
Class.new(Grape::API) do
namespace :SomeSpace, desc: 'Description for some space' do
get '/'
end
add_swagger_documentation format: :json
end
end

subject do
get '/swagger_doc'
JSON.parse(last_response.body)['apis'][0]
end

it 'shows the namespace description in the json spec' do
expect(subject['description']).to eql('Description for some space')
end
end
end
29 changes: 29 additions & 0 deletions spec/simple_mounted_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class SimpleMountedApi < Grape::API
{ bla: 'something' }
end

desc 'This gets something for URL in camelcase.',
notes: '_test_'
get '/SimpleTest' do
{ bla: 'something else' }
end

desc 'this gets something else',
headers: {
'XAuthToken' => { description: 'A required header.', required: true },
Expand Down Expand Up @@ -76,6 +82,7 @@ def app
'apis' => [
{ 'path' => '/simple.{format}', 'description' => 'Operations about simples' },
{ 'path' => '/simple-test.{format}', 'description' => 'Operations about simple-tests' },
{ 'path' => '/SimpleTest.{format}', 'description' => 'Operations about SimpleTests' },
{ 'path' => '/simple_with_headers.{format}', 'description' => 'Operations about simple_with_headers' },
{ 'path' => '/items.{format}', 'description' => 'Operations about items' },
{ 'path' => '/custom.{format}', 'description' => 'Operations about customs' },
Expand Down Expand Up @@ -129,6 +136,28 @@ def app
)
end

it 'uses camelcase' do
get '/swagger_doc/SimpleTest.json'
expect(JSON.parse(last_response.body)).to eq(
'apiVersion' => '0.1',
'swaggerVersion' => '1.2',
'basePath' => 'http://example.org',
'resourcePath' => '/SimpleTest',
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
'apis' => [{
'path' => '/SimpleTest.{format}',
'operations' => [{
'notes' => '_test_',
'summary' => 'This gets something for URL in camelcase.',
'nickname' => 'GET-SimpleTest---format-',
'method' => 'GET',
'parameters' => [],
'type' => 'void'
}]
}]
)
end

it 'includes headers' do
get '/swagger_doc/simple_with_headers.json'
expect(JSON.parse(last_response.body)['apis']).to eq [{
Expand Down