Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Union keys with union response types don't work when each response status has different media type #130

Open
tkow opened this issue Feb 12, 2024 · 0 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@tkow
Copy link
Contributor

tkow commented Feb 12, 2024

Steps To Reproduce

Remove this comment out , switch yaml from remote instead of local.

run bun i && bun ./gen.ts && npx tsc --noEmit ./src/client.ts in repo.

/accounts/{accountId}/urlscanner/scan/{scanId}/screenshot:
  get:
   ...
    200:
      content:
        "image/png":
    202:
      content:
        "application/json":

This generate types

type ResponseContentType$urlscanner$get$scan$screenshot = "image/png" |  "application/json
export const urlscanner$get$scan$screenshot = <RequestOption>(apiClient: ApiClient<RequestOption>) => <ResponseContentType extends ResponseContentType$urlscanner$get$scan$screenshot>(params: Params$urlscanner$get$scan$screenshot<ResponseContentType>, option?: RequestOption): Promise<(Response$urlscanner$get$scan$screenshot$Status$200 | Response$urlscanner$get$scan$screenshot$Status$202)[ResponseContentType]>

This emits an error because ResponseContentType keys require both types above to have all properties .

The current behavior

As ever described.

The expected behavior

Generate each ResponseContentType and union

<200ResponseContentType, 202ResponseContentType> ...
  Promise<
    Response$urlscanner$get$scan$screenshot$Status$200[200ResponseContentType] | 
    Response$urlscanner$get$scan$screenshot$Status$202)[202ResponseContentType]
>

or

  Promise<
    Response$urlscanner$get$scan$screenshot$Status$200[keyof  Response$urlscanner$get$scan$screenshot$Status$200] | 
    Response$urlscanner$get$scan$screenshot$Status$202[keyof Response$urlscanner$get$scan$screenshot$Status$202]
>

or

  <ResponseContentType extends {200: keyof 200Response, 202: keyof 202Response}>
  Promise<
    Response$urlscanner$get$scan$screenshot$Status$200[ResponseContentType['200']] | 
    Response$urlscanner$get$scan$screenshot$Status$202)[ResponseContentType['202']]
>

Final approach looks suitable for me.

@tkow tkow added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

1 participant