(config: Config)
| 323 | } |
| 324 | |
| 325 | async 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 | |
| 373 | export async function buildREADME( |
| 374 | pkgMgr: string, |
no test coverage detected