Skip to content

Commit 54de96d

Browse files
blakenumbata
authored andcommitted
Add test
1 parent 7f846a6 commit 54de96d

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'hidden flag enables a single endpoint parameter to be excluded from the documentation' do
6+
include_context "#{MODEL_PARSER} swagger example"
7+
before :all do
8+
module TheApi
9+
class HideParamsApi < Grape::API
10+
namespace :flat_params_endpoint do
11+
desc 'This is a endpoint with a flat parameter hierarchy'
12+
params do
13+
requires :name, type: String, documentation: { desc: 'name' }
14+
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 } }
16+
end
17+
18+
post do
19+
{ 'declared_params' => declared(params) }
20+
end
21+
end
22+
23+
namespace :nested_params_endpoint do
24+
desc 'This is a endpoint with a nested parameter hierarchy'
25+
params do
26+
optional :name, type: String, documentation: { desc: 'name' }
27+
optional :hidden_attribute, type: Hash do
28+
optional :favourite_color, type: String, documentation: { desc: 'I should not be anywhere', hidden: true }
29+
end
30+
31+
optional :attributes, type: Hash do
32+
optional :attribute_1, type: String, documentation: { desc: 'Attribute one' }
33+
optional :hidden_attribute, type: String, documentation: { desc: 'I should not be anywhere', hidden: true }
34+
end
35+
end
36+
37+
post do
38+
{ 'declared_params' => declared(params) }
39+
end
40+
end
41+
42+
namespace :required_param_endpoint do
43+
desc 'This endpoint has hidden defined for a required parameter'
44+
params do
45+
requires :name, type: String, documentation: { desc: 'name', hidden: true }
46+
end
47+
48+
post do
49+
{ 'declared_params' => declared(params) }
50+
end
51+
end
52+
53+
add_swagger_documentation openapi_version: '3.0'
54+
end
55+
end
56+
end
57+
58+
let(:app) { TheApi::HideParamsApi }
59+
60+
def property_names(path)
61+
subject['paths'][path]['post']['requestBody']['content']['application/x-www-form-urlencoded']['schema']['properties'].keys.map { |p| p['name'] }
62+
end
63+
64+
describe 'simple flat parameter hierarchy' do
65+
subject do
66+
get '/swagger_doc/flat_params_endpoint'
67+
JSON.parse(last_response.body)
68+
end
69+
70+
specify do
71+
expect(property_names('/flat_params_endpoint')).not_to include('favourite_color', 'proc_param')
72+
end
73+
end
74+
75+
describe 'nested parameter hierarchy' do
76+
subject do
77+
get '/swagger_doc/nested_params_endpoint'
78+
JSON.parse(last_response.body)
79+
end
80+
81+
specify do
82+
expect(property_names('/nested_params_endpoint')).not_to include(/hidden_attribute/)
83+
end
84+
end
85+
86+
describe 'hidden defined for required parameter' do
87+
subject do
88+
get '/swagger_doc/required_param_endpoint'
89+
JSON.parse(last_response.body)
90+
end
91+
92+
specify do
93+
expect(property_names('/required_param_endpoint')).to include('name')
94+
end
95+
end
96+
end

0 commit comments

Comments
 (0)