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

client.GET response type is "never" with apis that only define a default response type #1862

Open
1 task done
ArenM opened this issue Aug 19, 2024 · 0 comments
Open
1 task done
Labels
bug Something isn't working openapi-fetch Relevant to the openapi-fetch library

Comments

@ArenM
Copy link

ArenM commented Aug 19, 2024

Description

I'm writing a client for an api (which I don't control) that uses "default" as the type of the successful response. This isn't included in OkStatus which causes the response to be typed as never.

Reproduction

Generate a schema for this api and create a client from it.

const response = await client.GET("/versions", { params: {}});
console.log(response.data?.specifiedVersion);

This results in the following error: error TS2339: Property 'specifiedVersion' does not exist on type 'never'.

Expected result

No error generated (the code works when the error is ignored).

Checklist

  • I’m willing to open a PR (with feedback on whether to fix this in openapi-fetch or openapi-typescript)

Based on this https://spec.openapis.org/oas/v3.0.3#responses-object, I think using default for the success response type is allowed by the spec. I think this could either be fixed by a) adding "default" to OkStatus, or b) by adding logic to openapi-typescript to copy the default response type to a 2XX response if no other successful response type exists. I'm not sure what the unintended consequences of these would be.

@ArenM ArenM added bug Something isn't working openapi-fetch Relevant to the openapi-fetch library labels Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-fetch Relevant to the openapi-fetch library
Projects
None yet
Development

No branches or pull requests

1 participant