Skip to content

Commit ccdc6fa

Browse files
author
Tim Vandecasteele
committed
Merge branch 'pr/56'
2 parents 1fddab9 + 5c12185 commit ccdc6fa

File tree

3 files changed

+93
-5
lines changed

3 files changed

+93
-5
lines changed

CHANGELOG.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* Adding hidden endpoints - [@arturoherrero](https://github.com/arturoherrero).
66
* Fix: allow urls with `-` - [@dadario](https://github.com/dadario).
77
* Fix: mounting multiple documentations - [@Drakula2k](https://github.com/Drakula2k).
8+
* Fix: resource groupings for prefixed APIs - [@aew](https://github.com/aew).
9+
* Fix: hide_documentation_path on prefixed APIs - [@spier](https://github.com/spier).
810
* Your Contribution Here
911

1012
### 0.6.0 (June 19, 2013)

lib/grape-swagger.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ def add_swagger_documentation(options={})
1313

1414
@combined_routes = {}
1515
routes.each do |route|
16-
resource = route.route_path.match('\/([\w|-]*?)[\.\/\(]').captures.first
16+
resource = route.route_path.split(route.route_prefix).last.match('\/([\w|-]*?)[\.\/\(]').captures.first
1717
next if resource.empty?
1818
resource.downcase!
1919
@combined_routes[resource] ||= []
20-
@combined_routes[resource] << route
20+
21+
unless @@hide_documentation_path and route.route_path.include? @@mount_path
22+
@combined_routes[resource] << route
23+
end
2124
end
2225

2326
end

spec/non_default_api_spec.rb

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def app; SimpleApiWithVersionInPath end
115115

116116
it "gets the documentation on a versioned path /v1/swagger_doc" do
117117
get '/v1/swagger_doc.json'
118+
118119
JSON.parse(last_response.body).should == {
119120
"apiVersion" => "0.1",
120121
"swaggerVersion" => "1.1",
@@ -150,7 +151,6 @@ def app; SimpleApiWithVersionInPath end
150151

151152
context "overriding hiding the documentation paths" do
152153
before :all do
153-
154154
class HideDocumentationPathMountedApi < Grape::API
155155
desc 'This gets something.'
156156
get '/something' do
@@ -180,6 +180,88 @@ def app; SimpleApiWithHiddenDocumentation end
180180
end
181181
end
182182

183+
context "overriding hiding the documentation paths in prefixed API" do
184+
before :all do
185+
class HideDocumentationPathPrefixedMountedApi < Grape::API
186+
desc 'This gets something.'
187+
get '/something' do
188+
{ bla: 'something' }
189+
end
190+
end
191+
192+
class PrefixedApiWithHiddenDocumentation < Grape::API
193+
prefix "abc"
194+
mount HideDocumentationPathPrefixedMountedApi
195+
add_swagger_documentation :hide_documentation_path => true
196+
end
197+
198+
end
199+
200+
def app; PrefixedApiWithHiddenDocumentation end
201+
202+
it "it doesn't show the documentation path on /abc/swagger_doc/something.json" do
203+
get '/abc/swagger_doc/something.json'
204+
205+
JSON.parse(last_response.body).should == {
206+
"apiVersion"=>"0.1",
207+
"swaggerVersion"=>"1.1",
208+
"basePath"=>"http://example.org",
209+
"resourcePath"=>"",
210+
"apis"=>
211+
[{"path"=>"/abc/something.{format}",
212+
"operations"=>
213+
[{"notes"=>nil,
214+
"summary"=>"This gets something.",
215+
"nickname"=>"GET-abc-something---format-",
216+
"httpMethod"=>"GET",
217+
"parameters"=>[]}]}
218+
]}
219+
end
220+
221+
end
222+
223+
context "overriding hiding the documentation paths in prefixed and versioned API" do
224+
before :all do
225+
class HideDocumentationPathMountedApi2 < Grape::API
226+
desc 'This gets something.'
227+
get '/something' do
228+
{ bla: 'something' }
229+
end
230+
end
231+
232+
class PrefixedAndVersionedApiWithHiddenDocumentation < Grape::API
233+
prefix "abc"
234+
version 'v20', :using => :path
235+
236+
mount HideDocumentationPathMountedApi2
237+
238+
add_swagger_documentation :hide_documentation_path => true, :api_version => self.version
239+
end
240+
end
241+
242+
def app; PrefixedAndVersionedApiWithHiddenDocumentation end
243+
244+
it "it doesn't show the documentation path on /abc/v1/swagger_doc/something.json" do
245+
get '/abc/v20/swagger_doc/something.json'
246+
247+
JSON.parse(last_response.body).should == {
248+
"apiVersion"=>"v20",
249+
"swaggerVersion"=>"1.1",
250+
"basePath"=>"http://example.org",
251+
"resourcePath"=>"",
252+
"apis"=>
253+
[{"path"=>"/abc/v20/something.{format}",
254+
"operations"=>
255+
[{"notes"=>nil,
256+
"summary"=>"This gets something.",
257+
"nickname"=>"GET-abc--version-something---format-",
258+
"httpMethod"=>"GET",
259+
"parameters"=>[]}]}
260+
]}
261+
end
262+
263+
end
264+
183265
context "overriding the mount-path" do
184266
before :all do
185267
class DifferentMountMountedApi < Grape::API
@@ -257,7 +339,7 @@ def app; SimpleApiWithMarkdown end
257339
end
258340
end
259341

260-
context "versioned API" do
342+
context "prefixed and versioned API" do
261343
before :all do
262344
class VersionedMountedApi < Grape::API
263345
prefix 'api'
@@ -278,7 +360,8 @@ class SimpleApiWithVersion < Grape::API
278360
def app; SimpleApiWithVersion end
279361

280362
it "parses version and places it in the path" do
281-
get '/swagger_doc/api.json'
363+
get '/swagger_doc/something.json'
364+
282365
JSON.parse(last_response.body)["apis"].each do |api|
283366
api["path"].should start_with "/api/v1/"
284367
end

0 commit comments

Comments
 (0)