最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - migration from openapi-generator to openapi-typescript for types generation - Stack Overflow

programmeradmin0浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论