Skip to content

Using the same external ref multiple times generates types.gen.ts with invalid typescript #2551

@eoinkane

Description

@eoinkane

Description

Hello,

I was using the new version v0.82.0 which closed the issues:
1879
1135
668

However I am still having problems generating typescript types with specs that have multiple usages of the same external reference. I think this issue I am raising is closely related to the issues above

The types.gen.ts file is created successfully, with the first usage of the external ref resulting a in a valid type however the second usage of the same external ref results in a field without a type like so:

export type RetrieveData {
// ...
    channel: ;
};

This results in a typescript SyntaxError: Type expected.

I have managed to simplify my use case down to a reproducible repo and attached the stackblitz

I've tried to provide as much info as needed while removing any fluff that clutters the issue, let me know if there is anything else I can provide.

Thanks kindly,
Eoin

Reproducible example or configuration

https://stackblitz.com/~/github.com/eoinkane/hey-api-multi-ref

or go to the stack blitz for the #668 issue and bump the version to v0.82.0
https://stackblitz.com/edit/stackblitz-starters-kowe2x?file=src%2Fclient%2Ftypes.gen.ts

OpenAPI specification (optional)

schema1

openapi: 3.0.1
info:
  title: Service1
  description: The Service is responsible for managing data
  version: 1.0-SNAPSHOT
security:
  - bearerAuth: []
paths:
  /data:
    post:
      summary: |
        Creates a new data
      operationId: createData
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateDataRequest'
      responses:
        '201':
          description: Returns the created data
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Data'
components:
  schemas:
    DataUuid:
      type: string
      format: uuid
    Channel:
      type: string
      enum:
        - EMAIL
        - WEB
    CreateDataRequest:
      required:
        - firstName
        - lastName
      type: object
      properties:
        firstName:
          type: string
        lastName:
          type: string
    Data:
      required:
        - firstName
        - uuid
        - lastName
      type: object
      properties:
        firstName:
          type: string
        uuid:
          $ref: '#/components/schemas/DataUuid'
        lastName:
          type: string

schema2

openapi: 3.0.1
info:
  title: Messaging API for service
  description: An OpenAPI spec used for code generation for messaging
  version: 1.0-SNAPSHOT
paths: {}
components:
  schemas:
    CreateDataCommand:
      description: |
        This command will try to create data.
      required:
        - data
      type: object
      properties:
        data:
          $ref: '#/components/schemas/CreateData'
    CreateData:
      type: object
      required:
        - uuid
        - firstName
        - lastName
        - channel
      properties:
        uuid:
          $ref: 'service1-sync.yaml#/components/schemas/DataUuid'
        firstName:
          type: string
        lastName:
          type: string
        channel:
          $ref: 'service1-sync.yaml#/components/schemas/Channel'
    RetrieveDataCommand:
      description: |
        This command will try to retrieve data.
      required:
        - data
      type: object
      properties:
        data:
          $ref: '#/components/schemas/RetrieveData'
    RetrieveData:
      type: object
      required:
        - uuid
        - firstName
        - lastName
        - channel
      properties:
        uuid:
          $ref: 'service1-sync.yaml#/components/schemas/DataUuid'
        firstName:
          type: string
        lastName:
          type: string
        channel:
          $ref: 'service1-sync.yaml#/components/schemas/Channel'

System information (optional)

using MacOS sequoia 15.6, node v22.18.0 package version of @hey-api/openapi-ts is v.0.88.0

Metadata

Metadata

Assignees

Labels

bug 🔥Something isn't workingclientClient package relatedjavascriptPull requests that update Javascript code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions