Potential new config similar to unwrapResponseData
to include error in unwrapped response
#1236
Closed
Roman-Octavian
started this conversation in
General
Replies: 1 comment
-
I think this might actually be more suited for an issue so I will close it and write this issue instead: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Context
Specification
I have the following (shortened) OpenAPI spec:
openapi-spec.json
The takeaway from this specification is that I expect the return type to be something like this:
Reproduction
I generate a client from the specification above using
swagger-typescript-api
version13.1.3
:The problem
The client works, but
unwrapResponseData
only includes the response type for status200
, so the return type that I'm actually getting is this:The solution
If I want the return type to include the error, in the generated client, all I need to do is modify this line:
swagger-typescript-api/templates/base/http-clients/fetch-http-client.ejs
Line 172 in 0e251bb
To be
Instead of
And then my types work as expected:

Question
Would it be desirable to have another option
unwrapResponseDataWithErrors
or perhaps turnunwrapResponseData
into a union'disabled' | 'responseOnly' | 'responseAndError'
?So, here:
swagger-typescript-api/templates/base/http-clients/fetch-http-client.ejs
Lines 170 to 175 in 0e251bb
This could be something like this instead:
I am asking because maybe I am misunderstanding the intent behind
unwrapResponseData
and maybe this is not a good idea for reasons.If it's something that could be useful though, I am happy to make the changes in a PR.
Beta Was this translation helpful? Give feedback.
All reactions