openapi-typescript icon indicating copy to clipboard operation
openapi-typescript copied to clipboard

Generated schema type name starts with a number

Open SmallhillCZ opened this issue 10 months ago • 0 comments

openapi-typescript version

7.5.2

Node.js version

22.12.0

OS + version

Debian GNU/Linux 12 (bookworm)

Description

If I have multiple $ref in my operations schema like this:

paths:
  /some-path-1:
    get:
      operationId: SomeOperationName1
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: >-
                  http://localhost:3000/some-other-openapi.json#/paths/~1some-other-path-1/get/responses/200/content/application~1json/schema

  /some-path-2:
    get:
      operationId: SomeOperationName2
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: >-
                  http://localhost:3000/some-other-openapi.json#/paths/~1some-other-path-2/get/responses/200/content/application~1json/schema

  /some-path-3:
    get:
      operationId: SomeOperationName3
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: >-
                  http://localhost:3000/some-other-openapi.json#/paths/~1some-other-path-3/get/responses/200/content/application~1json/schema

the generated TypeScript will be:

export type Application_1jsonSchema = components['schemas']['application~1json-schema'];
export type ContentApplication_1jsonSchema = components['schemas']['content-application~1json-schema'];
export type 200ContentApplication_1jsonSchema = components['schemas']['200-content-application~1json-schema'];

Where the 200ContentApplication_1jsonSchema is invalid name for a type in TypeScript

Reproduction

See above

Expected result

Whatever name that does not start with a number, preferably one including operationId so I from which operation it is.

Required

  • [x] My OpenAPI schema is valid and passes the Redocly validator (npx @redocly/cli@latest lint)

Woohoo! Your API description is valid. 🎉

Extra

SmallhillCZ avatar Jan 30 '25 15:01 SmallhillCZ