Skip to content

Commit

Permalink
Prevent crashing when API has camelcase namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
gekola committed Dec 25, 2015
1 parent 4b72319 commit e5c16a7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
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

2 comments on commit e5c16a7

@rayko
Copy link

@rayko rayko commented on e5c16a7 Jun 15, 2016

Choose a reason for hiding this comment

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

This change vanished from the original repo in both master and 0.21.0 at the moment. I've opened the issue ruby-grape#457 in about this, and made a the request ruby-grape#458 that replays your work on the current master. I was having the same issue with camel case names and found your PR.

@gekola
Copy link
Owner Author

@gekola gekola commented on e5c16a7 Jun 16, 2016

Choose a reason for hiding this comment

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

Sorry for the delay, have been a bit busy recently. I currently use my fork that contains some minor editions, so haven't been following up with upstream changes for a while. Thank you for the notice.

Please sign in to comment.