@@ -492,5 +492,115 @@ describe('ts-rest-open-api', () => {
492492 )
493493 ) . toThrowError ( / g e t P o s t / ) ;
494494 } ) ;
495+
496+ it ( 'works with zod refine' , ( ) => {
497+ const routerWithRefine = c . router ( {
498+ endpointWithZodRefine : {
499+ method : 'GET' ,
500+ path : '/refine' ,
501+ responses : {
502+ 200 : c . response < null > ( ) ,
503+ } ,
504+ query : z
505+ . object ( {
506+ foo : z . string ( ) ,
507+ } )
508+ . refine ( ( v ) => v . foo === 'bar' , {
509+ message : 'foo must be bar' ,
510+ } ) ,
511+ } ,
512+ } ) ;
513+
514+ const schema = generateOpenApi ( routerWithRefine , {
515+ info : { title : 'Blog API' , version : '0.1' } ,
516+ } ) ;
517+
518+ expect ( schema ) . toEqual ( {
519+ info : {
520+ title : 'Blog API' ,
521+ version : '0.1' ,
522+ } ,
523+ openapi : '3.0.2' ,
524+ paths : {
525+ '/refine' : {
526+ get : {
527+ deprecated : undefined ,
528+ description : undefined ,
529+ parameters : [
530+ {
531+ in : 'query' ,
532+ name : 'foo' ,
533+ required : true ,
534+ schema : {
535+ type : 'string' ,
536+ } ,
537+ } ,
538+ ] ,
539+ responses : {
540+ '200' : {
541+ description : '200' ,
542+ } ,
543+ } ,
544+ summary : undefined ,
545+ tags : [ ] ,
546+ } ,
547+ } ,
548+ } ,
549+ } ) ;
550+ } ) ;
551+
552+ it ( 'works with zod transform' , ( ) => {
553+ const routerWithTransform = c . router ( {
554+ endpointWithZodTransform : {
555+ method : 'GET' ,
556+ path : '/transform' ,
557+ responses : {
558+ 200 : c . response < null > ( ) ,
559+ } ,
560+ query : z
561+ . object ( {
562+ foo : z . string ( ) ,
563+ } )
564+ . transform ( ( v ) => ( { fooTransformed : v . foo } ) ) ,
565+ } ,
566+ } ) ;
567+
568+ const schema = generateOpenApi ( routerWithTransform , {
569+ info : { title : 'Blog API' , version : '0.1' } ,
570+ } ) ;
571+
572+ expect ( schema ) . toEqual ( {
573+ info : {
574+ title : 'Blog API' ,
575+ version : '0.1' ,
576+ } ,
577+ openapi : '3.0.2' ,
578+ paths : {
579+ '/transform' : {
580+ get : {
581+ deprecated : undefined ,
582+ description : undefined ,
583+ parameters : [
584+ {
585+ in : 'query' ,
586+ name : 'foo' ,
587+ required : true ,
588+ schema : {
589+ type : 'string' ,
590+ } ,
591+ } ,
592+ ] ,
593+ responses : {
594+ '200' : {
595+ description : '200' ,
596+ } ,
597+ } ,
598+ summary : undefined ,
599+ tags : [ ] ,
600+ } ,
601+ } ,
602+ } ,
603+ } ) ;
604+ } ) ;
495605 } ) ;
496606} ) ;
0 commit comments