Skip to content

Commit 1fddab9

Browse files
author
Tim Vandecasteele
committed
Merge branch 'pr/57'
2 parents 3ffd95d + f0ef658 commit 1fddab9

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

CHANGELOG.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Adding support for generating swagger responseClass and models from Grape Entities - [@calebwoods](https://github.com/calebwoods).
55
* Adding hidden endpoints - [@arturoherrero](https://github.com/arturoherrero).
66
* Fix: allow urls with `-` - [@dadario](https://github.com/dadario).
7+
* Fix: mounting multiple documentations - [@Drakula2k](https://github.com/Drakula2k).
78
* Your Contribution Here
89

910
### 0.6.0 (June 19, 2013)

lib/grape-swagger.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def self.setup(options)
4646
}
4747
options = defaults.merge(options)
4848

49-
@@target_class = options[:target_class]
49+
target_class = options[:target_class]
5050
@@mount_path = options[:mount_path]
5151
@@class_name = options[:class_name] || options[:mount_path].gsub('/','')
5252
@@markdown = options[:markdown]
@@ -59,7 +59,7 @@ def self.setup(options)
5959
get @@mount_path do
6060
header['Access-Control-Allow-Origin'] = '*'
6161
header['Access-Control-Request-Method'] = '*'
62-
routes = @@target_class::combined_routes
62+
routes = target_class::combined_routes
6363

6464
if @@hide_documentation_path
6565
routes.reject!{ |route, value| "/#{route}/".index(parse_path(@@mount_path, nil) << '/') == 0 }
@@ -87,8 +87,8 @@ def self.setup(options)
8787
header['Access-Control-Allow-Origin'] = '*'
8888
header['Access-Control-Request-Method'] = '*'
8989
models = []
90-
routes = @@target_class::combined_routes[params[:name]]
91-
routes_array = routes.map { |route|
90+
routes = target_class::combined_routes[params[:name]]
91+
routes_array = routes.map {|route|
9292
next if route.route_hidden
9393
notes = route.route_notes && @@markdown ? Kramdown::Document.new(strip_heredoc(route.route_notes)).to_html : route.route_notes
9494
http_codes = parse_http_codes route.route_http_codes

spec/non_default_api_spec.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,59 @@ def app; SimpleApiWithHiddenPaths; end
337337
end
338338
end
339339
end
340+
341+
context "multiple documentations" do
342+
before :all do
343+
class FirstApi < Grape::API
344+
desc 'This is the first API'
345+
get '/first' do
346+
{ first: 'hip' }
347+
end
348+
349+
add_swagger_documentation mount_path: '/first/swagger_doc'
350+
end
351+
352+
class SecondApi < Grape::API
353+
desc 'This is the second API'
354+
get '/second' do
355+
{ second: 'hop' }
356+
end
357+
358+
add_swagger_documentation mount_path: '/second/swagger_doc'
359+
end
360+
361+
class SimpleApiWithMultipleMountedDocumentations < Grape::API
362+
mount FirstApi
363+
mount SecondApi
364+
end
365+
end
366+
367+
def app; SimpleApiWithMultipleMountedDocumentations; end
368+
369+
it "retrieves the first swagger-documentation on /first/swagger_doc" do
370+
get '/first/swagger_doc.json'
371+
JSON.parse(last_response.body).should == {
372+
"apiVersion" => "0.1",
373+
"swaggerVersion" => "1.1",
374+
"basePath" => "http://example.org",
375+
"operations" => [],
376+
"apis" => [
377+
{ "path" => "/first/swagger_doc/first.{format}" }
378+
]
379+
}
380+
end
381+
382+
it "retrieves the first swagger-documentation on /second/swagger_doc" do
383+
get '/second/swagger_doc.json'
384+
JSON.parse(last_response.body).should == {
385+
"apiVersion" => "0.1",
386+
"swaggerVersion" => "1.1",
387+
"basePath" => "http://example.org",
388+
"operations" => [],
389+
"apis" => [
390+
{ "path" => "/second/swagger_doc/second.{format}" }
391+
]
392+
}
393+
end
394+
end
340395
end

0 commit comments

Comments
 (0)