orval icon indicating copy to clipboard operation
orval copied to clipboard

Allow `fetch`client's `data` to be set to success type only

Open soartec-lab opened this issue 7 months ago • 6 comments

Background

In #1885, we defined the type of response's data and status as a combination. When used with the fetch client, this is a more accurate type definition.

However, when used as an HTTP client such as swr or react-query, it becomes a union type of 200 and 400, and the type cannot be specified. And in those libraries, it is common to use exceptions for cases other than 200 and refer to data only when it is 200.

For example, swr:

https://swr.vercel.app/docs/error-handling

Proposal

There are cases where you want to define only 200 data as before and make only the status a union type, so by making these options selectable, we would like to maintain the format before #1885.

soartec-lab avatar Apr 19 '25 07:04 soartec-lab

Hi @AllieJonsson what do you think about this?

soartec-lab avatar Apr 19 '25 07:04 soartec-lab

Seems very reasonable. Is there a need to have this as a setting? Im thinking maybe this should be the behavior when using fetch as httpClient, and keep the behavior introduced in #1885 when using fetch as client?

AllieJonsson avatar Apr 19 '25 09:04 AllieJonsson

@AllieJonsson Although swr and tanstack query are recommended, they are not mandatory. There may be cases where you want to use composite response types while using those libraries, so we want to maintain the option for users.

soartec-lab avatar Apr 20 '25 01:04 soartec-lab

Hi, is there any movement on this or do you need someone to help contribute it?

jeremy-marcus avatar Jun 05 '25 13:06 jeremy-marcus

Hi, @jeremy-marcus. There is nothing going on. We would be happy to accept your contribute!

soartec-lab avatar Jun 06 '25 00:06 soartec-lab

I'm looking into this now :)

AllieJonsson avatar Jun 17 '25 07:06 AllieJonsson