@@ -5,13 +5,12 @@ import {
55 AppRouteMutation ,
66 AppRouteQuery ,
77 AppRouter ,
8- isAppRoute ,
8+ checkZodSchema ,
99 getValue ,
10+ isAppRoute ,
11+ PathParamsWithCustomValidators ,
1012 Without ,
1113 ZodInferOrType ,
12- PathParams ,
13- checkZodSchema ,
14- Merge ,
1514} from '@ts-rest/core' ;
1615
1716export type ApiRouteResponse < T > = {
@@ -24,7 +23,7 @@ export type ApiRouteResponse<T> = {
2423type AppRouteQueryImplementation < T extends AppRouteQuery > = (
2524 input : Without <
2625 {
27- params : PathParamsWithZod < T > ;
26+ params : PathParamsWithCustomValidators < T > ;
2827 query : ZodInferOrType < T [ 'query' ] > ;
2928 headers : IncomingHttpHeaders ;
3029 req : Request ;
@@ -38,17 +37,10 @@ type WithoutFileIfMultiPart<T extends AppRouteMutation> =
3837 ? Without < ZodInferOrType < T [ 'body' ] > , File >
3938 : ZodInferOrType < T [ 'body' ] > ;
4039
41- /**
42- * Merge PathParams<T> with pathParams schema if it exists
43- */
44- type PathParamsWithZod < T extends AppRoute > = T [ 'pathParams' ] extends undefined
45- ? PathParams < T >
46- : Merge < PathParams < T > , ZodInferOrType < T [ 'pathParams' ] > > ;
47-
4840type AppRouteMutationImplementation < T extends AppRouteMutation > = (
4941 input : Without <
5042 {
51- params : PathParamsWithZod < T > ;
43+ params : PathParamsWithCustomValidators < T > ;
5244 query : ZodInferOrType < T [ 'query' ] > ;
5345 body : WithoutFileIfMultiPart < T > ;
5446 headers : IncomingHttpHeaders ;
@@ -82,10 +74,8 @@ export const initServer = () => {
8274} ;
8375
8476const recursivelyApplyExpressRouter = (
85- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8677 router : RecursiveRouterObj < any > | AppRouteImplementation < any > ,
8778 path : string [ ] ,
88- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8979 routeTransformer : ( route : AppRouteImplementation < any > , path : string [ ] ) => void
9080) : void => {
9181 if ( typeof router === 'object' ) {
@@ -102,7 +92,6 @@ const recursivelyApplyExpressRouter = (
10292} ;
10393
10494const transformAppRouteQueryImplementation = (
105- // eslint-disable-next-line @typescript-eslint/no-explicit-any
10695 route : AppRouteQueryImplementation < any > ,
10796 schema : AppRouteQuery ,
10897 app : IRouter
@@ -124,9 +113,7 @@ const transformAppRouteQueryImplementation = (
124113 return res . status ( 400 ) . send ( paramsResult . error ) ;
125114 }
126115
127- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
128116 const result = await route ( {
129- // @ts -ignore
130117 params : paramsResult . data ,
131118 query : queryResult . data ,
132119 headers : req . headers ,
@@ -138,7 +125,6 @@ const transformAppRouteQueryImplementation = (
138125} ;
139126
140127const transformAppRouteMutationImplementation = (
141- // eslint-disable-next-line @typescript-eslint/no-explicit-any
142128 route : AppRouteMutationImplementation < any > ,
143129 schema : AppRouteMutation ,
144130 app : IRouter
@@ -161,18 +147,22 @@ const transformAppRouteMutationImplementation = (
161147 return res . status ( 400 ) . send ( bodyResult . error ) ;
162148 }
163149
150+ const paramsResult = checkZodSchema ( req . params , schema . pathParams , {
151+ passThroughExtraKeys : true ,
152+ } ) ;
153+
154+ if ( ! paramsResult . success ) {
155+ return res . status ( 400 ) . send ( paramsResult . error ) ;
156+ }
157+
164158 const result = await route ( {
165- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
166- // @ts -ignore
167- params : req . params ,
159+ params : paramsResult . data ,
168160 body : bodyResult . data ,
169161 query : queryResult . data ,
170162 headers : req . headers ,
171- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
172- // @ts -ignore
163+ // @ts -expect-error
173164 files : req . files ,
174- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
175- // @ts -ignore
165+ // @ts -expect-error
176166 file : req . file ,
177167 req : req ,
178168 } ) ;
@@ -220,7 +210,6 @@ export const createExpressEndpoints = <
220210 transformAppRouteMutationImplementation ( route , routerViaPath , app ) ;
221211 } else {
222212 transformAppRouteQueryImplementation (
223- // eslint-disable-next-line @typescript-eslint/no-explicit-any
224213 route as AppRouteQueryImplementation < any > ,
225214 routerViaPath ,
226215 app
0 commit comments