Skip to content

Commit d4bae9b

Browse files
committed
Merge pull request #172 from grzesiek/doc-fix
Fix problem with using prefix name somewhere in api paths
2 parents e977fea + ba02fdb commit d4bae9b

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* [#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).
66
* [#169](https://github.com/tim-vandecasteele/grape-swagger/pull/169): Test against multiple versions of Grape - [@dblock](https://github.com/dblock).
77
* [#166](https://github.com/tim-vandecasteele/grape-swagger/pull/166): Ensure compatibility with Grape 0.8.0 or newer - [@dblock](https://github.com/dblock).
8+
* [#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).
9+
810
* Your contribution here.
911

1012
### 0.8.0 (August 30, 2014)

lib/grape-swagger.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def add_swagger_documentation(options = {})
1717

1818
@combined_routes = {}
1919
routes.each do |route|
20-
route_match = route.route_path.split(route.route_prefix).last.match('\/([\w|-]*?)[\.\/\(]')
20+
route_match = route.route_path.split(/^.*?#{route.route_prefix.to_s}/).last.match('\/([\w|-]*?)[\.\/\(]')
2121
next if route_match.nil?
2222
resource = route_match.captures.first
2323
next if resource.empty?

spec/api_paths_spec.rb

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
require 'spec_helper'
2+
3+
describe 'simple api with prefix' do
4+
5+
before :all do
6+
class ApiWithPrefix < Grape::API
7+
prefix :api
8+
9+
desc 'This gets apitest'
10+
get '/apitest' do
11+
{ test: 'something' }
12+
end
13+
end
14+
15+
class SimpleApiWithPrefix < Grape::API
16+
mount ApiWithPrefix
17+
add_swagger_documentation
18+
end
19+
20+
end
21+
22+
def app
23+
SimpleApiWithPrefix
24+
end
25+
26+
it 'should not raise TypeError exception' do
27+
end
28+
29+
it 'retrieves swagger-documentation on /swagger_doc that contains apitest' do
30+
get '/swagger_doc.json'
31+
expect(JSON.parse(last_response.body)).to eq(
32+
'apiVersion' => '0.1',
33+
'swaggerVersion' => '1.2',
34+
'info' => {},
35+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
36+
'apis' => [
37+
{ 'path' => '/apitest.{format}', 'description' => 'Operations about apitests' },
38+
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
39+
]
40+
)
41+
end
42+
43+
context 'retrieves the documentation for apitest that' do
44+
it 'contains returns something in URL' do
45+
get '/swagger_doc/apitest.json'
46+
expect(JSON.parse(last_response.body)).to eq(
47+
'apiVersion' => '0.1',
48+
'swaggerVersion' => '1.2',
49+
'basePath' => 'http://example.org',
50+
'resourcePath' => '/apitest',
51+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
52+
'apis' => [{
53+
'path' => '/api/apitest.{format}',
54+
'operations' => [{
55+
'notes' => '',
56+
'summary' => 'This gets apitest',
57+
'nickname' => 'GET-api-apitest---format-',
58+
'method' => 'GET',
59+
'parameters' => [],
60+
'type' => 'void'
61+
}]
62+
}]
63+
)
64+
end
65+
end
66+
67+
end

0 commit comments

Comments
 (0)