I am migrating the code from OpenAPI Generator to OpenAPI TypeScript to generate the types. Currently, I have written the following piece of code that generates the types,
const ast = await openapiTS(this.readFile('petStore.yaml'));
const contents = astToString(ast);
fs1.writeFileSync('./generated/my-schema1.ts', contents);
The types are generated in a format similar to the OpenAPI specification, where only components, paths, and operations are exported. This makes the migration challenging, as I need to import these types in this specific manner like below.
generateOrder(
@Body() order: components['schemas']['Order'],
): components['schemas']['Order'] {
console.log('order id : ' + order.id);
return order;
}
instead of
generateOrder(
@Body() order: Order,
): Order {
console.log('order id : ' + order.id);
return order;
}
We need a way to import the types directly, rather than using the current method of importing them as components['schemas']['Order']. This approach necessitates significant refactoring across multiple applications.
Is there a way to export each component of the OpenAPI schema as individual types that can be imported directly?
I have used petstore sample openapi for this above example