Skip to content

Commit 5015d44

Browse files
author
Tim Vandecasteele
committed
Add possibility to hide the documentation paths in the generated swagger documentation.
1 parent e2336f3 commit 5015d44

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

README.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ You can pass a hash with some configuration possibilities to ```add_swagger_docu
4141
* ```:api_version``` Version of the API that's being exposed
4242
* ```:base_path``` Basepath of the API that's being exposed
4343
* ```:markdown``` Allow markdown in `notes`, default `false`
44+
* ```:hide_documentation_path``` Don't show the '/swagger_doc' path in the generated swagger documentation
4445

4546
## Swagger Header Parameters
4647

lib/grape-swagger.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ def self.setup(options)
4141
:mount_path => '/swagger_doc',
4242
:base_path => nil,
4343
:api_version => '0.1',
44-
:markdown => false
44+
:markdown => false,
45+
:hide_documentation_path => false
4546
}
4647
options = defaults.merge(options)
4748

4849
@@target_class = options[:target_class]
4950
@@mount_path = options[:mount_path]
5051
@@class_name = options[:class_name] || options[:mount_path].gsub('/','')
5152
@@markdown = options[:markdown]
53+
@@hide_documentation_path = options[:hide_documentation_path]
5254
api_version = options[:api_version]
5355
base_path = options[:base_path]
5456

@@ -58,6 +60,10 @@ def self.setup(options)
5860
header['Access-Control-Request-Method'] = '*'
5961
routes = @@target_class::combined_routes
6062

63+
if @@hide_documentation_path
64+
routes.reject!{ |route, value| "/#{route}/".index(parse_path(@@mount_path, nil) << '/') == 0 }
65+
end
66+
6167
routes_array = routes.keys.map do |route|
6268
{ :path => "#{@@mount_path}/#{route}.{format}" }
6369
end

spec/non_default_api_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,29 @@ def app; SimpleApiWithApiVersion end
6161
end
6262
end
6363

64+
context "overruling hiding the documentation paths" do
65+
before(:all) do
66+
class HideDocumentationPathMountedApi < Grape::API
67+
desc 'this gets something'
68+
get '/something' do
69+
{:bla => 'something'}
70+
end
71+
end
72+
73+
class SimpleApiWithHiddenDocumentation < Grape::API
74+
mount HideDocumentationPathMountedApi
75+
add_swagger_documentation :hide_documentation_path => true
76+
end
77+
end
78+
79+
def app; SimpleApiWithHiddenDocumentation end
80+
81+
it "it doesn't show the documentation path on /swagger_doc" do
82+
get '/swagger_doc'
83+
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :operations=>[], :apis=>[{:path=>\"/swagger_doc/something.{format}\"}]}"
84+
end
85+
end
86+
6487
context "overruling the mount-path" do
6588
before(:all) do
6689
class DifferentMountMountedApi < Grape::API

0 commit comments

Comments
 (0)