Skip to content

Commit dcb82de

Browse files
arturoherreroTim Vandecasteele
authored andcommitted
Hide endpoint from the swagger documentation. Resolves #24
Use hidden symbol in the description block: desc 'Hide an endpoint', { :hidden => true }
1 parent f2717ff commit dcb82de

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

lib/grape-swagger.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ def self.setup(options)
6666
end
6767

6868
routes_array = routes.keys.map do |local_route|
69+
next if routes[local_route].any? { |route| route.route_hidden }
6970
{ :path => "#{parse_path(route.route_path.gsub('(.:format)', ''),route.route_version)}/#{local_route}#{@@hide_format ? '' : '.{format}'}" }
70-
end
71+
end.compact
7172

7273
{
7374
apiVersion: api_version,

spec/hide_api_spec.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
require 'spec_helper'
2+
3+
describe "a hide mounted api" do
4+
before :all do
5+
class HideMountedApi < Grape::API
6+
desc 'Show this endpoint'
7+
get '/simple' do
8+
{ :bla => 'something' }
9+
end
10+
11+
desc 'Hide this endpoint', {
12+
:hidden => true
13+
}
14+
get '/hide' do
15+
{ :bla => 'something_else' }
16+
end
17+
end
18+
19+
class HideApi < Grape::API
20+
mount HideMountedApi
21+
add_swagger_documentation
22+
end
23+
end
24+
25+
def app; HideApi end
26+
27+
it "retrieves swagger-documentation on /swagger_doc" do
28+
get '/swagger_doc.json'
29+
JSON.parse(last_response.body).should == {
30+
"apiVersion" => "0.1",
31+
"swaggerVersion" => "1.1",
32+
"basePath" => "http://example.org",
33+
"operations" => [],
34+
"apis" => [
35+
{ "path" => "/swagger_doc/simple.{format}" },
36+
{ "path" => "/swagger_doc/swagger_doc.{format}" }
37+
]
38+
}
39+
end
40+
end

0 commit comments

Comments
 (0)