Skip to content

Incorrect TypeScript generated when using true TS enums and top-level type exports without prefix #2341

Open
@conTroll

Description

@conTroll

openapi-typescript version

7.8.0

Node.js version

22.16.0

OS + version

macOS 15.5

Description

When generating the types with true TS enums instead of union types and top-level type exports without the Schema prefix the resulting TS file has errors, because of the overlapping export definitions. For example, given an enum type in the openAPI schema called Permission, you get the following two exports will happen under the same name in the resulting TS file:

export type Permission = components['schemas']['Permission'];

export enum Permission {
    Read = "Read",
    Write = "Write"
}

This does not happen if we export union types instead of enums, then the first export type Permission will be the same:

export type Permission = components['schemas']['Permission'];

but the union type is defined inline in the schema and not exported separately:

/** @enum {string} */
Permission: "Read" | "Write"

Reproduction

Generate a TS API for an OpenAPI schema that contains any enum type with the following options:

--root-types --root-types-no-schema-prefix --enum

Expected result

The resulting code passes the TS compiler without errors.

Required

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

Extra

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopenapi-tsRelevant to the openapi-typescript library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions