hey-api / openapi-ts

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

Query params shouldn't accept `Record<string, unknown>` #1247

Open jpenna opened 2 weeks ago

jpenna commented 2 weeks ago

Description

The lib is generating a union with Record<string, unknown> for query parameters, which doesn't throw type errors when the query schema changes.

I realized it also happens for body if it isn't defined (check the sample code). I think it should be never when it isn't defined.

Maybe add a configuration like --use-never to default any unset value to never.

Reproducible example or configuration

Check App.tsx:73

https://stackblitz.com/edit/hey-api-client-fetch-example-ssbzuv?file=src%2FApp.tsx&view=editor

OpenAPI specification (optional)

Use the example above.

System information (optional)

@hey-api/openapi-ts: v0.53.6

stackblitz[bot] commented 2 weeks ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

mrlubos commented 2 weeks ago

Hi @jpenna, can you try with the experimental parser? I think it might be fixed there https://heyapi.dev/openapi-ts/configuration.html#parser

jpenna commented 1 week ago

@mrlubos Will try it Monday!

jpenna commented 3 days ago

Hello @mrlubos , I just upgraded to the latest version 0.53.12 and added the option for the parser (it is actually experimental_parser with underscore, according to the types).

But it is still including the Record<string, unknown>

 path: Record<string, unknown> & {
    threadId: string;
mrlubos commented 3 days ago

Thanks for confirming, will fix!