mirror of
https://github.com/Dvorinka/Bookra.git
synced 2026-06-04 04:22:59 +00:00
18 lines
685 B
JavaScript
18 lines
685 B
JavaScript
import fs from "node:fs/promises";
|
|
import path from "node:path";
|
|
import { pathToFileURL } from "node:url";
|
|
import openapiTS, { astToString } from "openapi-typescript";
|
|
|
|
const rootDir = path.resolve(import.meta.dirname, "../../..");
|
|
const specPath = path.resolve(rootDir, "apps/backend/openapi/bookra.openapi.yaml");
|
|
const outputPath = path.resolve(import.meta.dirname, "../src/generated/types.ts");
|
|
|
|
const ast = await openapiTS(pathToFileURL(specPath), {
|
|
alphabetize: true,
|
|
});
|
|
const schema = astToString(ast);
|
|
|
|
await fs.mkdir(path.dirname(outputPath), { recursive: true });
|
|
await fs.writeFile(outputPath, `${schema}\n`, "utf8");
|
|
console.log(`Generated API types to ${outputPath}`);
|