redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

Proposal[rtk-query-codegen-openapi]: Override query body name

Open RobinGranstromKall opened this issue 2 years ago • 1 comments

I have an api that i'm consuming with pretty long schema names in most places. I had the thought that i don't really care what the name of the request body is since i have already specified to use that endpoint. I'm not sure why its useful to have a name for the body that is the same as the operation. For example if i generate an api from the petstore:

addPet: build.mutation<AddPetApiResponse, AddPetApiArg>({
        query: (queryArg) => ({
          url: `/pet`,
          method: "POST",
          body: queryArg.pet,
        }),
        invalidatesTags: ["pet"],
      })

I would like to be able to configure the generator to not "guess" the name for queryArg.pet and instead write something like queryArg.body for every endpoint. I would like the type to remain AddPetApiArg.

I think i know how i would do this in the generator code and submit a PR. But i wanted to first check if that is something that would be accepted. Or perhaps someone has some other suggestion that would solve this issue, if it helps i do have access to the generation of the specification and can alter that.

RobinGranstromKall avatar Nov 29 '22 14:11 RobinGranstromKall

bit late to the party, but strong +1 to this

we also have some verbose k8s schema names, so a simple POST ends up looking like:

addQueryTemplate({
  comGithubGrafanaGrafanaPkgApisPeakqV0Alpha1QueryTemplate: <data>
})

looking at the code, it looks like it falls back to body if there are any naming clashes. would the maintainers be opposed to swapping that to default to body and falling back to the more verbose names if body clashes? 🤔

ashharrison90 avatar Jan 21 '25 17:01 ashharrison90