MCPcopy Index your code
hub / github.com/ProNextJS/declarative-routing / writeOpenAPI

Function writeOpenAPI

src/shared/build-tools.ts:325–371  ·  view source on GitHub ↗
(config: Config)

Source from the content-addressed store, hash-verified

323}
324
325async function writeOpenAPI(config: Config) {
326 if (!config.openapi) return;
327
328 let template = fs.readFileSync(config.openapi.template).toString();
329
330 const imports: string[] = [];
331 const registrations: string[] = [];
332
333 const pathPrefix = config.routes
334 .replace("./", "")
335 .split("/")
336 .map(() => "..")
337 .join("/");
338
339 for (const path of Object.values(paths)) {
340 if (path.verbs.length > 0) {
341 imports.push(
342 await buildStringFromTemplate("shared/openapi-import.template", {
343 importKey: path.importKey,
344 pathPrefix,
345 srcDir: (config.src || "").replace("./", ""),
346 import: path.infoPath.replace(".ts", "")
347 })
348 );
349 for (const verb of path.verbs) {
350 registrations.push(
351 await buildStringFromTemplate("shared/openapi-register.template", {
352 lowerVerb: verb.toLowerCase(),
353 pathTemplate: path.pathTemplate.replace(/\[(.*)\]/g, '{$1}'),
354 verb,
355 importKey: path.importKey,
356 isNotDELETE: verb !== "DELETE",
357 isPOSTorPUT: verb === "PUT" || verb === "POST"
358 })
359 );
360 }
361 }
362 }
363
364 template = template.replace(/\/\/ \{\{IMPORTS\}\}/, imports.join("\n"));
365 template = template.replace(
366 /\/\/ \{\{REGISTRATIONS\}\}/,
367 registrations.join("\n")
368 );
369
370 fs.writeFileSync(config.openapi.target, template);
371}
372
373export async function buildREADME(
374 pkgMgr: string,

Callers 2

buildFilesFunction · 0.85
updateBuildFilesFunction · 0.85

Calls 1

buildStringFromTemplateFunction · 0.90

Tested by

no test coverage detected