@@ -25,7 +25,7 @@ import {
25
25
} from '../model/metamodel'
26
26
27
27
// use npm run dump-routes --prefix compiler -- --debug to print the Go debug map
28
- const debugTestRoutes = argv . debug ?? false
28
+ const debugRoutes : boolean = argv . debug ?? false
29
29
const outputPath = argv . output ?? join ( __dirname , '..' , '..' , '..' , 'output' , 'schema' , 'routes.go' )
30
30
const V8SchemaUrl = join ( __dirname , '..' , '..' , '..' , 'output' , 'schema' , 'schema.json' )
31
31
const V7SchemaUrl = 'https://raw.githubusercontent.com/elastic/elasticsearch-specification/7.17/output/schema/schema.json'
@@ -290,26 +290,26 @@ async function extractRoutesFromFiles (outPath: string): Promise<void> {
290
290
const v7Spec = await v7Schema . text ( )
291
291
292
292
const serverlessSpec = await readFile (
293
- serverlessSchemaUrl ,
294
- { encoding : 'utf8' }
293
+ serverlessSchemaUrl ,
294
+ { encoding : 'utf8' }
295
295
)
296
296
297
297
const versions = new Map < string , string > ( )
298
- versions . set ( "7" , v7Spec )
299
- versions . set ( "8" , v8Spec )
300
- versions . set ( " serverless" , serverlessSpec )
298
+ versions . set ( '7' , v7Spec )
299
+ versions . set ( '8' , v8Spec )
300
+ versions . set ( ' serverless' , serverlessSpec )
301
301
302
302
const forest = new Forest ( )
303
303
304
304
versions . forEach ( function ( spec , version ) {
305
305
const inputModel = JSON . parse ( spec )
306
- if ( debugTestRoutes ) {
307
- debug_test_routes ( version , inputModel )
306
+ if ( debugRoutes ) {
307
+ debugTestRoutes ( version , inputModel )
308
308
}
309
309
const routes = extractRoutes ( inputModel )
310
310
forest . byVersion . set ( version , routes )
311
311
} )
312
- forest . byVersion . set ( "0" , defaultRoutes ( ) )
312
+ forest . byVersion . set ( '0' , defaultRoutes ( ) )
313
313
314
314
const str = serializeForest ( forest )
315
315
@@ -562,30 +562,30 @@ function defaultRoutes (): Trees {
562
562
return t
563
563
}
564
564
565
- function debug_test_routes ( version : string , inputModel : Model ) {
566
- console . log ( version ) ;
565
+ function debugTestRoutes ( version : string , inputModel : Model ) : void {
566
+ console . log ( version )
567
567
568
- let output = new Map < string , Map < string , string > [ ] > ( ) ;
568
+ const output = new Map < string , Array < Map < string , string > > > ( )
569
569
570
- for ( const endpoint of inputModel . endpoints ) {
571
- for ( const url of endpoint . urls ) {
572
- for ( const method of url . methods ) {
573
- if ( ! output . has ( method ) ) {
574
- output . set ( method , [ ] )
575
- }
576
- let newPath = url . path . replace ( new RegExp ( "\{|\}" , 'g' ) , "" )
577
- output . get ( method ) ?. push ( new Map < string , string > ( [ [ newPath , endpoint . name ] ] ) ) ;
578
- }
570
+ for ( const endpoint of inputModel . endpoints ) {
571
+ for ( const url of endpoint . urls ) {
572
+ for ( const method of url . methods ) {
573
+ if ( ! output . has ( method ) ) {
574
+ output . set ( method , [ ] )
579
575
}
576
+ const newPath = url . path . replace ( / \{ | \} / g, '' )
577
+ output . get ( method ) ?. push ( new Map < string , string > ( [ [ newPath , endpoint . name ] ] ) )
578
+ }
580
579
}
580
+ }
581
581
582
- output . forEach ( ( urls , method ) => {
583
- console . log ( '"%s": {' , method )
584
- urls . forEach ( ( path ) => {
585
- path . forEach ( ( name , path ) => {
586
- console . log ( '{"%s", "%s"},' , path , name )
587
- } )
588
- } )
589
- console . log ( "}," )
582
+ output . forEach ( ( urls , method ) => {
583
+ console . log ( '"%s": {' , method )
584
+ urls . forEach ( ( path ) => {
585
+ path . forEach ( ( name , path ) => {
586
+ console . log ( '{"%s", "%s"},' , path , name )
587
+ } )
590
588
} )
589
+ console . log ( '},' )
590
+ } )
591
591
}
0 commit comments