@@ -122,6 +122,62 @@ def define_optional_using
122122 end
123123 end
124124
125+ context 'requires with nested params' do
126+ before do
127+ subject . params do
128+ requires :first_level , type : Hash do
129+ optional :second_level , type : Array do
130+ requires :value , type : Integer
131+ optional :name , type : String
132+ optional :third_level , type : Array do
133+ requires :value , type : Integer
134+ optional :name , type : String
135+ optional :fourth_level , type : Array do
136+ requires :value , type : Integer
137+ optional :name , type : String
138+ end
139+ end
140+ end
141+ end
142+ end
143+ subject . put ( '/required' ) { 'required works' }
144+ end
145+
146+ let ( :request_params ) do
147+ {
148+ first_level : {
149+ second_level : [
150+ { value : 1 , name : 'Lisa' } ,
151+ {
152+ value : 2 ,
153+ name : 'James' ,
154+ third_level : [
155+ { value : 'three' , name : 'Sophie' } ,
156+ {
157+ value : 4 ,
158+ name : 'Jenny' ,
159+ fourth_level : [
160+ { name : 'Samuel' } , { value : 6 , name : 'Jane' }
161+ ]
162+ }
163+ ]
164+ }
165+ ]
166+ }
167+ }
168+ end
169+
170+ it 'validates correctly in deep nested params' do
171+ put '/required' , request_params . to_json , 'CONTENT_TYPE' => 'application/json'
172+
173+ expect ( last_response . status ) . to eq ( 400 )
174+ expect ( last_response . body ) . to eq (
175+ 'first_level[second_level][1][third_level][0][value] is invalid, ' \
176+ 'first_level[second_level][1][third_level][1][fourth_level][0][value] is missing'
177+ )
178+ end
179+ end
180+
125181 context 'requires :all using Grape::Entity documentation' do
126182 def define_requires_all
127183 documentation = {
0 commit comments