Skip to content

Commit ab6fc95

Browse files
spierTim Vandecasteele
authored andcommitted
Fixing the :hide_documentation_path option for prefixed APIs
1 parent 7d24f86 commit ab6fc95

File tree

2 files changed

+87
-2
lines changed

2 files changed

+87
-2
lines changed

lib/grape-swagger.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ def add_swagger_documentation(options={})
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: 83 additions & 1 deletion
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 HideDocumentationPathMountedApi < 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 HideDocumentationPathMountedApi
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/abc.json" do
203+
get '/abc/swagger_doc/abc.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/abc.json" do
245+
get '/abc/v20/swagger_doc/abc.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

0 commit comments

Comments
 (0)