reduxjs / redux-toolkit

The official, opinionated, batteries-included toolset for efficient Redux development
https://redux-toolkit.js.org
MIT License
10.69k stars 1.16k forks source link

Add an option to encode query arguments in openApi codegen #3822

Closed ifozest closed 1 month ago

ifozest commented 11 months ago

Hi all,

Currently, there is no way to specify that query arguments should be encoded when generating OpenAPI code using rtk query codegen. This can be a problem if you are using an argument with special characters, such as #.

For example, the following query function would result in an OpenAPI endpoint:

    doFoo: build.mutation<void, { foo: string, ... }>({
      query: (queryArg) => ({
        url: `/api/${queryArg.foo}`,
        method: "POST",
        body: queryArg.requestObject,
      }),
    }),

To fix this, I would like to request an option to enable query argument encoding in OpenAPI codegen. This would generate the following query function and generate an encoded endpoint: /api/${encodeURIComponent(queryArg.foo)} or similar

I believe that this would be a valuable addition to rtk query openAPI codegen, as it would make it easier to use query args with special characters.

Thank you for your consideration.

Meantime I'm using injectEndpoints and overwriting them which is not ideal.

rjgotten commented 10 months ago

Technically this is a correctness problem, isn't it? Anything going into an URI path should be encoded as an URI component, period.

shivam178 commented 8 months ago

I faced the same issue. Used encodeURIComponent in the same way to overcome it. I'm facing this issue only in Safari and Firefox and it's working fine in Chromium browsers as they seem auto encode URLs before requesting them.

Richard87 commented 4 months ago

I was just bit by this issue in Chrome and absolutley agree this should be handled in the API Client library... Is there any fix available?

Or would RTK team accept a PR to add this?

bayasdev commented 1 month ago

I'm facing the same issue, would a fix be available soon?

Edit: nvm sent a PR