Skip to content

Commit 587c542

Browse files
committed
add debug helper for routes
1 parent 8c388aa commit 587c542

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

compiler/src/dump/extract-routes.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import {
2424
Model
2525
} from '../model/metamodel'
2626

27+
// use npm run dump-routes --prefix compiler -- --debug to print the Go debug map
28+
const debugTestRoutes = argv.debug ?? false
2729
const outputPath = argv.output ?? join(__dirname, '..', '..', '..', 'output', 'schema', 'routes.go')
2830
const V8SchemaUrl = join(__dirname, '..', '..', '..', 'output', 'schema', 'schema.json')
2931
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> {
301303

302304
versions.forEach(function (spec, version) {
303305
const inputModel = JSON.parse(spec)
306+
if (debugTestRoutes) {
307+
debug_test_routes(version, inputModel)
308+
}
304309
const routes = extractRoutes(inputModel)
305310
forest.byVersion.set(version, routes)
306311
})
@@ -556,3 +561,31 @@ function defaultRoutes (): Trees {
556561

557562
return t
558563
}
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

Comments
 (0)