Replies: 1 comment
-
There is an However, in our case we use the same tooling to generate types from different OpenAPI schemas, and don't know beforehand whether a given format is actually used in a schema, so a static Instead, we track the usage out-of-band, and interpolate the openapi-typescript generated // Track whether the import is necessary
let hasObjectId = false;
const typesOutput = await openapiTS(localPath, {
// ...other options
transform: (schema) => {
if ('format' in schemaObject && schemaObject.format === 'mongo-objectid') {
// This side-effect signals that the import is necessary
hasObjectId = true;
return ts.factory.createTypeReferenceNode('ObjectId');
}
}
});
const output = `${
// include imports if necessary
hasObjectId ?
"import { ObjectId } from 'mongodb';\n\n" :
''
}${
// stringify the openapi-typescript nodes
astToString(typesOutput)
}`;
fs.writeFileSync("interfaces.d.ts", output); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Description
This is more a basic question than a bug.
I am following the Node.js API docs with the example of replacing
Date
andDateTime
. I would like to use a custom library (e.g.luxon
) to provide these types.My script
The resulting
interfaces.d.ts
file has the types mapped correctlyhowever
DateTime
is unresolved.How do I inject
import { DateTime } from 'luxon';
intointerfaces.d.ts
?Beta Was this translation helpful? Give feedback.
All reactions