Incorrect TypeScript generated when using true TS enums and top-level type exports without prefix · Issue #2341 · openapi-ts/openapi-typescript · GitHub
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
This is a valid bug, but one of the main hazards in trying to expose different parts of your schema as top-level exports.
I believe this issue a duplicate of #2099 (and likely many others).
@conTroll Given the names of the component schemas you're using here, what would you expect the resulting exports to look like?
I checked your referenced issue and you are correct, this is a duplicate of #2099 .
My expectation would be the following:
The top-level type exports referring to components['schemas']['...'] can be omitted, if there is a corresponding enum export under that same name. It would be still registered under components['schemas'] so references would not break. In my generated code if I delete the following lines
export type Permission = components['schemas']['Permission'];
for only the enum types I get exactly what I would expect to get, and our app works as expected with the queries being called in Tanstack Query using openapi-fetch 0.14.0 .
Uh oh!
There was an error while loading. Please reload this page.
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 calledPermission
, you get the following two exports will happen under the same name in the resulting TS file:This does not happen if we export union types instead of enums, then the first export type Permission will be the same:
but the union type is defined inline in the schema and not exported separately:
Reproduction
Generate a TS API for an OpenAPI schema that contains any enum type with the following options:
Expected result
The resulting code passes the TS compiler without errors.
Required
npx @redocly/cli@latest lint
)Extra
The text was updated successfully, but these errors were encountered: