mirror of
https://github.com/gotson/komga.git
synced 2025-12-08 01:24:31 +01:00
26 lines
838 B
TypeScript
26 lines
838 B
TypeScript
import fs from "node:fs";
|
|
import openapiTS, { astToString } from "openapi-typescript";
|
|
import ts from "typescript";
|
|
|
|
// From https://openapi-ts.dev/node
|
|
// We use the Node.js API as the CLI does not support Date types
|
|
|
|
const mySchema = new URL("../komga/docs/openapi.json", import.meta.url)
|
|
|
|
const DATE = ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("Date")); // `Date`
|
|
const NULL = ts.factory.createLiteralTypeNode(ts.factory.createNull()); // `null`
|
|
|
|
const ast = await openapiTS(mySchema, {
|
|
transform(schemaObject) {
|
|
if (schemaObject.format === "date-time") {
|
|
return schemaObject.nullable
|
|
? ts.factory.createUnionTypeNode([DATE, NULL])
|
|
: DATE;
|
|
}
|
|
},
|
|
});
|
|
|
|
const contents = astToString(ast);
|
|
|
|
// (optional) write to file
|
|
fs.writeFileSync("./src/generated/openapi/komga.d.ts", contents);
|