hey-api / openapi-ts

🚀 The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more. Support: @mrlubos
https://heyapi.dev
Other
1.28k stars 102 forks source link

Incorrect TypeScript types generated (union types lost) #484

Closed paambaati closed 6 months ago

paambaati commented 6 months ago

Description

I've recently started migrating https://github.com/paambaati/neon-js-sdk from openapi-typescript-codegen to @hey-api/openapi-ts, and I've run into an error in the generated output.

Consider the following snippet of code (where NeonClient is the main class from the generated output) –

const neonClient = new NeonClient({
    TOKEN: '<INSERT NEON API KEY HERE>',
});

const projects = await neonClient.project.listProjects();
console.log(projects);

The type for the listProjects() function should be CancelablePromise<(ProjectsResponse & PaginationResponse) | GeneralError> – see https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgOQKYQHYGEA2xUbwC+cAZlBCHAOQboYC0AzgCYDW1A3AFDcDGmJvDqZc+QnAC8cOgHcU9MQRgAKBNzia4AFQDyAaQCiyAFw0APAElkAZUMAlbSkO7kcAIIAFS3CMBNOAAJB0MAPmoAGm4iAEoebhUAQyYATww+OBUYqVDEDS0BDCE4MAoAK1Q+GCYpOETZROBhRTxlADpSiAqqtrwhT3LK6qyeLThCpggcVF6IAHMVTu7quOiYrKA

Screenshot 2024-04-24 at 12 05 26 PM

However, in the generated output using this package, the type for listProjects() becomes CancelablePromise<GeneralError>.

Screenshot 2024-04-24 at 12 08 09 PM

The bug here is that the first union type is lost.

OpenAPI specification (optional)

https://dfv3qgd2ykmrx.cloudfront.net/api_spec/release/v2.json

Configuration

openapi-ts --name NeonClient --client fetch --input https://dfv3qgd2ykmrx.cloudfront.net/api_spec/release/v2.json --output ./generated

System information (optional)

OS: Darwin MacBook-Pro.local 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:25 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6030 arm64 Package version: 0.42.1 Node.js version: 21.7.3

mrlubos commented 6 months ago

Thanks for reporting @paambaati!

mrlubos commented 6 months ago

@paambaati this will be fixed in the next release, please let me know if that works for you once you try it!