openapistack / openapi-client-axios

JavaScript client library for consuming OpenAPI-enabled APIs with axios
https://openapistack.co
MIT License
550 stars 67 forks source link

DTOs are not reused. Instead the whole contents are inserted. #121

Closed nicu-chiciuc closed 1 year ago

nicu-chiciuc commented 2 years ago

We're using Nest.js with swagger and we have a script that generates a *.d.ts files using typegen like so:

typegen ./path-to-openapi/generated/openapi.json > ./path-to-generated/client.generated.d.ts

The issue is that we have some DTOs that are used inside other dtos, for example:

"MainDto": {
  "type": "object",
  "properties": {
    // ... Other properties
    "reused_data": {
      "description": "Some description",
      "allOf": [{ "$ref": "#/components/schemas/ReusedDto" }]
    },
  },
},

// ... After some lines
"ReusedDto": {
  "type": "object",
  "properties": {
    "some_email": { "type": "string", "nullable": true },
  },
  "required": ["some_email"]
  },

And after running typegen the result is this:

export interface MainDto {
  reused_data?: {
    some_email: string | null;
  };
  }
// ... some other types
export interface ReusedDto {
  some_email: string | null;
}

Is it possible to instead generate it like this instead?

    export interface MainDto {
      reused_data?: ReusedDto;
    }

We're currently using version 3.14.1, but I've also tested this on the latest version: 5.0.2.

anttiviljami commented 1 year ago

Unfortunately that behaviour is from the upstream library https://github.com/horiuchi/dtsgenerator