Skip to content

Fix problem with using prefix name somewhere in api paths #172

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

Merged
merged 1 commit into from
Nov 13, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* [#162](https://github.com/tim-vandecasteele/grape-swagger/pull/162): Fix performance issue related to having a large number of models - [@elado](https://github.com/elado).
* [#169](https://github.com/tim-vandecasteele/grape-swagger/pull/169): Test against multiple versions of Grape - [@dblock](https://github.com/dblock).
* [#166](https://github.com/tim-vandecasteele/grape-swagger/pull/166): Ensure compatibility with Grape 0.8.0 or newer - [@dblock](https://github.com/dblock).
* [#174](https://github.com/tim-vandecasteele/grape-swagger/pull/172): Fix problem with using prefix name somewhere in api paths - [@grzesiek](https://github.com/grzesiek).

* Your contribution here.

### 0.8.0 (August 30, 2014)
Expand Down
2 changes: 1 addition & 1 deletion lib/grape-swagger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def add_swagger_documentation(options = {})

@combined_routes = {}
routes.each do |route|
route_match = route.route_path.split(route.route_prefix).last.match('\/([\w|-]*?)[\.\/\(]')
route_match = route.route_path.split(/^.*?#{route.route_prefix.to_s}/).last.match('\/([\w|-]*?)[\.\/\(]')
next if route_match.nil?
resource = route_match.captures.first
next if resource.empty?
Expand Down
67 changes: 67 additions & 0 deletions spec/api_paths_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require 'spec_helper'

describe 'simple api with prefix' do

before :all do
class ApiWithPrefix < Grape::API
prefix :api

desc 'This gets apitest'
get '/apitest' do
{ test: 'something' }
end
end

class SimpleApiWithPrefix < Grape::API
mount ApiWithPrefix
add_swagger_documentation
end

end

def app
SimpleApiWithPrefix
end

it 'should not raise TypeError exception' do
end

it 'retrieves swagger-documentation on /swagger_doc that contains apitest' do
get '/swagger_doc.json'
expect(JSON.parse(last_response.body)).to eq(
'apiVersion' => '0.1',
'swaggerVersion' => '1.2',
'info' => {},
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
'apis' => [
{ 'path' => '/apitest.{format}', 'description' => 'Operations about apitests' },
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
]
)
end

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

end