openapi-typescript icon indicating copy to clipboard operation
openapi-typescript copied to clipboard

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

Open ArenM opened this issue 1 year ago • 0 comments

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

  • [x] 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 avatar Aug 19 '24 18:08 ArenM