-
-
Notifications
You must be signed in to change notification settings - Fork 615
Closed
Labels
bugSomething isn't workingSomething isn't workingopenapi-tsRelevant to the openapi-typescript libraryRelevant to the openapi-typescript library
Description
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 ?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingopenapi-tsRelevant to the openapi-typescript libraryRelevant to the openapi-typescript library
Type
Projects
Status
Done