Open
Description
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
- I’m willing to open a PR (see CONTRIBUTING.md)