Skip to content

Commit 6d8b9fb

Browse files
Use resource as root for swagger.
iso of class name of mounted class.
1 parent f18258c commit 6d8b9fb

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

lib/grape-swagger.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ class << self
88
def mount(mounts)
99
original_mount mounts
1010
@combined_routes ||= {}
11-
@combined_routes[mounts.name.split('::').last.downcase] = mounts::routes
11+
mounts::routes.each do |route|
12+
resource = route.route_path.match('\/(.*?)[\.\/\(]').captures.first || '/'
13+
@combined_routes[resource.downcase] ||= []
14+
@combined_routes[resource.downcase] << route
15+
end
1216
end
1317

1418
def add_swagger_documentation(options={})

spec/non_default_api_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ def app; subject end
2323

2424
it "retrieves the given base-path on /swagger_doc" do
2525
get '/swagger_doc'
26-
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"#{SimpleApiWithBasePath::NON_DEFAULT_BASE_PATH}\", :operations=>[], :apis=>[{:path=>\"/swagger_doc/mountedapi.{format}\"}, {:path=>\"/swagger_doc/swagger_doc.{format}\"}]}"
26+
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"#{SimpleApiWithBasePath::NON_DEFAULT_BASE_PATH}\", :operations=>[], :apis=>[{:path=>\"/swagger_doc/something.{format}\"}, {:path=>\"/swagger_doc/swagger_doc.{format}\"}]}"
2727
end
2828

2929
it "retrieves the same given base-path for mounted-api" do
3030
Random.stub(:rand) { 0 }
31-
get '/swagger_doc/mountedapi'
31+
get '/swagger_doc/something'
3232
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"#{SimpleApiWithBasePath::NON_DEFAULT_BASE_PATH}\", :resourcePath=>\"\", :apis=>[{:path=>\"/something.{format}\", :operations=>[{:notes=>nil, :summary=>\"this gets something\", :nickname=>0, :httpMethod=>\"GET\", :parameters=>[]}]}]}"
3333
end
3434
end
@@ -46,12 +46,12 @@ def app; subject end
4646

4747
it "retrieves the given base-path on /swagger_doc" do
4848
get '/swagger_doc'
49-
last_response.body.should == "{:apiVersion=>\"#{SimpleApiWithAPiVersion::API_VERSION}\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :operations=>[], :apis=>[{:path=>\"/swagger_doc/mountedapi.{format}\"}, {:path=>\"/swagger_doc/swagger_doc.{format}\"}]}"
49+
last_response.body.should == "{:apiVersion=>\"#{SimpleApiWithAPiVersion::API_VERSION}\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :operations=>[], :apis=>[{:path=>\"/swagger_doc/something.{format}\"}, {:path=>\"/swagger_doc/swagger_doc.{format}\"}]}"
5050
end
5151

5252
it "retrieves the same given base-path for mounted-api" do
5353
Random.stub(:rand) { 0 }
54-
get '/swagger_doc/mountedapi'
54+
get '/swagger_doc/something'
5555
last_response.body.should == "{:apiVersion=>\"#{SimpleApiWithAPiVersion::API_VERSION}\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :resourcePath=>\"\", :apis=>[{:path=>\"/something.{format}\", :operations=>[{:notes=>nil, :summary=>\"this gets something\", :nickname=>0, :httpMethod=>\"GET\", :parameters=>[]}]}]}"
5656
end
5757
end
@@ -69,12 +69,12 @@ def app; subject end
6969

7070
it "retrieves the given base-path on /swagger_doc" do
7171
get '/api_doc'
72-
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :operations=>[], :apis=>[{:path=>\"/swagger_doc/mountedapi.{format}\"}, {:path=>\"/swagger_doc/swagger_doc.{format}\"}]}"
72+
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :operations=>[], :apis=>[{:path=>\"/swagger_doc/something.{format}\"}, {:path=>\"/swagger_doc/swagger_doc.{format}\"}]}"
7373
end
7474

7575
it "retrieves the same given base-path for mounted-api" do
7676
Random.stub(:rand) { 0 }
77-
get '/api_doc/mountedapi'
77+
get '/api_doc/something'
7878
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :resourcePath=>\"\", :apis=>[{:path=>\"/something.{format}\", :operations=>[{:notes=>nil, :summary=>\"this gets something\", :nickname=>0, :httpMethod=>\"GET\", :parameters=>[]}]}]}"
7979
end
8080

@@ -85,4 +85,4 @@ def app; subject end
8585
end
8686

8787

88-
end
88+
end

spec/simple_mounted_api_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ def app; subject end
1919

2020
it "retrieves swagger-documentation on /swagger_doc" do
2121
get '/swagger_doc'
22-
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :operations=>[], :apis=>[{:path=>\"/swagger_doc/mountedapi.{format}\"}, {:path=>\"/swagger_doc/swagger_doc.{format}\"}]}"
22+
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :operations=>[], :apis=>[{:path=>\"/swagger_doc/something.{format}\"}, {:path=>\"/swagger_doc/swagger_doc.{format}\"}]}"
2323
end
2424

2525
it "retrieves the documentation for mounted-api" do
2626
Random.stub(:rand) { 0 }
27-
get '/swagger_doc/mountedapi'
27+
get '/swagger_doc/something'
2828
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :resourcePath=>\"\", :apis=>[{:path=>\"/something.{format}\", :operations=>[{:notes=>nil, :summary=>\"this gets something\", :nickname=>0, :httpMethod=>\"GET\", :parameters=>[]}]}]}"
2929
end
30-
end
30+
end

0 commit comments

Comments
 (0)