7
7
before :all do
8
8
module TheApi
9
9
class HideParamsApi < Grape ::API
10
+ helpers do
11
+ def resource_owner
12
+ '123'
13
+ end
14
+ end
15
+
10
16
namespace :flat_params_endpoint do
11
17
desc 'This is a endpoint with a flat parameter hierarchy'
12
18
params do
13
19
requires :name , type : String , documentation : { desc : 'name' }
14
20
optional :favourite_color , type : String , documentation : { desc : 'I should not be anywhere' , hidden : true }
15
- optional :proc_param , type : String , documentation : { desc : 'I should not be anywhere' , hidden : -> { true } }
21
+ optional :proc_param , type : String , documentation : { desc : 'I should not be anywhere' , hidden : proc { true } }
22
+ optional :proc_with_token , type : String , documentation : { desc : 'I may be somewhere' , hidden : proc { |token_owner = nil | token_owner . nil? } }
16
23
end
17
24
18
25
post do
@@ -50,7 +57,7 @@ class HideParamsApi < Grape::API
50
57
end
51
58
end
52
59
53
- add_swagger_documentation
60
+ add_swagger_documentation token_owner : 'resource_owner'
54
61
end
55
62
end
56
63
end
@@ -63,9 +70,13 @@ class HideParamsApi < Grape::API
63
70
JSON . parse ( last_response . body )
64
71
end
65
72
66
- specify do
73
+ it 'ignores parameters that are explicitly hidden' do
67
74
expect ( subject [ 'paths' ] [ '/flat_params_endpoint' ] [ 'post' ] [ 'parameters' ] . map { |p | p [ 'name' ] } ) . not_to include ( 'favourite_color' , 'proc_param' )
68
75
end
76
+
77
+ it 'allows procs to consult the token_owner' do
78
+ expect ( subject [ 'paths' ] [ '/flat_params_endpoint' ] [ 'post' ] [ 'parameters' ] . map { |p | p [ 'name' ] } ) . to include ( 'proc_with_token' )
79
+ end
69
80
end
70
81
71
82
describe 'nested parameter hierarchy' do
0 commit comments