Description
This is more a basic question than a bug.
I am following the Node.js API docs with the example of replacing Date and DateTime. I would like to use a custom library (e.g. luxon) to provide these types.
My script
import ts from "typescript";
import openapiTS, { astToString } from "openapi-typescript";
import fs from "node:fs";
const DATE_TIME = ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("DateTime"));
const DATE = ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("Date"));
const NULL = ts.factory.createLiteralTypeNode(ts.factory.createNull());
const localPath = new URL("../../api/openapi.yaml", import.meta.url);
const output = await openapiTS(localPath,{
transform(schemaObject, metadata) {
if (["date-time", "date"].includes(schemaObject.format)) {
return schemaObject.nullable
? ts.factory.createUnionTypeNode([DATE_TIME, NULL])
: DATE_TIME;
}
},
});
fs.writeFileSync("interfaces.d.ts", astToString(output))
The resulting interfaces.d.ts file has the types mapped correctly
schemas: {
Id: string;
String: string;
/** Format: date-time */
DateTime: DateTime;
Date: DateTime;
...
}
however DateTime is unresolved.
How do I inject import { DateTime } from 'luxon'; into interfaces.d.ts ?
Description
This is more a basic question than a bug.
I am following the Node.js API docs with the example of replacing
DateandDateTime. I would like to use a custom library (e.g.luxon) to provide these types.My script
The resulting
interfaces.d.tsfile has the types mapped correctlyhowever
DateTimeis unresolved.How do I inject
import { DateTime } from 'luxon';intointerfaces.d.ts?