@@ -230,6 +230,60 @@ export default class RouteTest {
230230 assert . deepEqual ( response . json ( ) , { id : 10 , limit : 2 } )
231231 }
232232
233+ @Test ( )
234+ public async shouldExposeParsedZodValuesThroughAllRequestAccessors ( { assert } : Context ) {
235+ Route . post ( 'users/:published' , async ctx => {
236+ await ctx . response . send ( {
237+ body : ctx . request . input ( 'syncProfile' ) ,
238+ bodyFromGetter : ctx . request . body . syncProfile ,
239+ header : ctx . request . header ( 'x-with-profile' ) ,
240+ headerFromGetter : ctx . request . headers [ 'x-with-profile' ] ,
241+ param : ctx . request . param ( 'published' ) ,
242+ paramFromGetter : ctx . request . params . published ,
243+ query : ctx . request . query ( 'withProfile' ) ,
244+ queryFromGetter : ctx . request . queries . withProfile
245+ } )
246+ } ) . schema ( {
247+ body : z . object ( { syncProfile : z . stringbool ( ) } ) ,
248+ headers : z . object ( { 'x-with-profile' : z . stringbool ( ) } ) ,
249+ params : z . object ( { published : z . stringbool ( ) } ) ,
250+ querystring : z . object ( { withProfile : z . stringbool ( ) } ) ,
251+ response : {
252+ 200 : z . object ( {
253+ body : z . boolean ( ) ,
254+ bodyFromGetter : z . boolean ( ) ,
255+ header : z . boolean ( ) ,
256+ headerFromGetter : z . boolean ( ) ,
257+ param : z . boolean ( ) ,
258+ paramFromGetter : z . boolean ( ) ,
259+ query : z . boolean ( ) ,
260+ queryFromGetter : z . boolean ( )
261+ } )
262+ }
263+ } )
264+
265+ Route . register ( )
266+
267+ const response = await Server . request ( {
268+ path : '/users/true?withProfile=true' ,
269+ method : 'post' ,
270+ headers : { 'x-with-profile' : 'false' } ,
271+ payload : { syncProfile : 'true' }
272+ } )
273+
274+ assert . equal ( response . statusCode , 200 )
275+ assert . deepEqual ( response . json ( ) , {
276+ body : true ,
277+ bodyFromGetter : true ,
278+ header : false ,
279+ headerFromGetter : false ,
280+ param : true ,
281+ paramFromGetter : true ,
282+ query : true ,
283+ queryFromGetter : true
284+ } )
285+ }
286+
233287 @Test ( )
234288 @Cleanup ( ( ) => Config . set ( 'openapi.paths' , { } ) )
235289 public async shouldAutomaticallyApplySchemasFromOpenApiConfig ( { assert } : Context ) {
@@ -266,6 +320,55 @@ export default class RouteTest {
266320 assert . deepEqual ( response . json ( ) , { id : 10 , limit : 2 } )
267321 }
268322
323+ @Test ( )
324+ @Cleanup ( ( ) => Config . set ( 'openapi.paths' , { } ) )
325+ public async shouldAutomaticallyExposeParsedOpenApiZodValuesInRequestAccessors ( { assert } : Context ) {
326+ Config . set ( 'openapi.paths' , {
327+ '/users/{published}' : {
328+ post : {
329+ body : z . object ( { syncProfile : z . stringbool ( ) } ) ,
330+ headers : z . object ( { 'x-with-profile' : z . stringbool ( ) } ) ,
331+ params : z . object ( { published : z . stringbool ( ) } ) ,
332+ querystring : z . object ( { withProfile : z . stringbool ( ) } ) ,
333+ response : {
334+ 200 : z . object ( {
335+ body : z . boolean ( ) ,
336+ header : z . boolean ( ) ,
337+ param : z . boolean ( ) ,
338+ query : z . boolean ( )
339+ } )
340+ }
341+ }
342+ }
343+ } )
344+
345+ Route . post ( 'users/:published' , async ctx => {
346+ await ctx . response . send ( {
347+ body : ctx . request . input ( 'syncProfile' ) ,
348+ header : ctx . request . header ( 'x-with-profile' ) ,
349+ param : ctx . request . param ( 'published' ) ,
350+ query : ctx . request . query ( 'withProfile' )
351+ } )
352+ } )
353+
354+ Route . register ( )
355+
356+ const response = await Server . request ( {
357+ path : '/users/true?withProfile=false' ,
358+ method : 'post' ,
359+ headers : { 'x-with-profile' : 'true' } ,
360+ payload : { syncProfile : 'false' }
361+ } )
362+
363+ assert . equal ( response . statusCode , 200 )
364+ assert . deepEqual ( response . json ( ) , {
365+ body : false ,
366+ header : true ,
367+ param : true ,
368+ query : false
369+ } )
370+ }
371+
269372 @Test ( )
270373 public async shouldBeAbleToHideARouteFromTheSwaggerDocumentation ( { assert } : Context ) {
271374 Route . get ( 'test' , new HelloController ( ) . index )
0 commit comments