@@ -153,6 +153,12 @@ async function runGenerate(result, spec) {
153153 includeWrapper : "react-query" ,
154154 } ,
155155 } ,
156+ router : {
157+ target : {
158+ library : "koa" ,
159+ } ,
160+ exposeApiStructure : true ,
161+ } ,
156162 } ,
157163 } ) ;
158164
@@ -173,7 +179,6 @@ async function runGenerate(result, spec) {
173179 resolveJsonModule : true ,
174180 isolatedModules : true ,
175181 jsx : "preserve" ,
176- noImplicitAny : false ,
177182 } ,
178183 exclude : [ "node_modules" ] ,
179184 include : [ "**/*.ts" , "**/*.d.ts" , "**/*.tsx" ] ,
@@ -268,8 +273,72 @@ async function runValidator(result, spec) {
268273 * @param {SpecResult } result
269274 * @param {import("../spec/specification.js").CodeGenSpecificationRouteMatcher } spec
270275 */
271- function runRouteMatcher ( result , spec ) {
272- result . skipped ++ ;
276+ async function runRouteMatcher ( result , spec ) {
277+ try {
278+ const { routeMatcher } = await import (
279+ pathJoin (
280+ process . cwd ( ) ,
281+ generateOutputDirectory ,
282+ `common/route-matcher.js` ,
283+ )
284+ ) ;
285+
286+ const routeMatch = routeMatcher (
287+ spec . matchInput . method ,
288+ spec . matchInput . path ,
289+ ) ;
273290
274- return spec ;
291+ if ( isNil ( routeMatch ) && isNil ( spec . matchOutput ) ) {
292+ result . passed ++ ;
293+ } else if ( isNil ( spec . matchOutput ) ) {
294+ throw AppError . serverError ( {
295+ message : "Expected no route match, but found a match" ,
296+ spec,
297+ routeMatch,
298+ } ) ;
299+ } else if ( isNil ( routeMatch ) ) {
300+ throw AppError . serverError ( {
301+ message : "Expected a route match, but found no match" ,
302+ spec,
303+ } ) ;
304+ } else {
305+ if (
306+ routeMatch . route . group !== spec . matchOutput . route . group ||
307+ routeMatch . route . name !== spec . matchOutput . route . name
308+ ) {
309+ throw AppError . serverError ( {
310+ message : "Matched an invalid route" ,
311+ spec,
312+ routeMatch,
313+ } ) ;
314+ }
315+
316+ if (
317+ Object . keys ( routeMatch . params ) . length !==
318+ Object . keys ( spec . matchOutput . params ) . length
319+ ) {
320+ throw AppError . serverError ( {
321+ message : "Did not match the appropriate number of params" ,
322+ spec,
323+ routeMatch,
324+ } ) ;
325+ }
326+
327+ for ( const [ key , value ] of Object . entries ( spec . matchOutput . params ) ) {
328+ if ( routeMatch . params [ key ] !== value ) {
329+ throw AppError . serverError ( {
330+ message : "Matched an invalid route param" ,
331+ spec,
332+ routeMatch,
333+ } ) ;
334+ }
335+ }
336+
337+ result . passed ++ ;
338+ }
339+ } catch ( e ) {
340+ result . failed ++ ;
341+ result . extraLogs . push ( `Failed to route match at ${ formatSpecPath ( result ) } ` ) ;
342+ result . extraLogs . push ( AppError . format ( e ) ) ;
343+ }
275344}
0 commit comments