@@ -24,6 +24,8 @@ import {
24
24
Model
25
25
} from '../model/metamodel'
26
26
27
+ // use npm run dump-routes --prefix compiler -- --debug to print the Go debug map
28
+ const debugTestRoutes = argv . debug ?? false
27
29
const outputPath = argv . output ?? join ( __dirname , '..' , '..' , '..' , 'output' , 'schema' , 'routes.go' )
28
30
const V8SchemaUrl = join ( __dirname , '..' , '..' , '..' , 'output' , 'schema' , 'schema.json' )
29
31
const V7SchemaUrl = 'https://raw.githubusercontent.com/elastic/elasticsearch-specification/7.17/output/schema/schema.json'
@@ -301,6 +303,9 @@ async function extractRoutesFromFiles (outPath: string): Promise<void> {
301
303
302
304
versions . forEach ( function ( spec , version ) {
303
305
const inputModel = JSON . parse ( spec )
306
+ if ( debugTestRoutes ) {
307
+ debug_test_routes ( version , inputModel )
308
+ }
304
309
const routes = extractRoutes ( inputModel )
305
310
forest . byVersion . set ( version , routes )
306
311
} )
@@ -556,3 +561,31 @@ function defaultRoutes (): Trees {
556
561
557
562
return t
558
563
}
564
+
565
+ function debug_test_routes ( version : string , inputModel : Model ) {
566
+ console . log ( version ) ;
567
+
568
+ let output = new Map < string , Map < string , string > [ ] > ( ) ;
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
+ }
579
+ }
580
+ }
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 ( "}," )
590
+ } )
591
+ }
0 commit comments