You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@rtk-query/openapi-codegen generates what looks like the correct code:
getFoos: build.query<GetFoosApiResponse,GetFoosApiArg>({query: (queryArg)=>({url: `/store/foos/page`,params: {params: queryArg.params},}),}),/* … */exporttypeGetFoosApiResponse=/** status 200 OK */FoosPage;exporttypeGetFoosApiArg={params: {[key: string]: string;};};
And I call it like this (with React hooks):
const{ data }=useGetFoosQuery({params: {foo: "bar",baz: "quux"}});
I’d expect this to make a request with a query string like this:
?foo=bar&baz=quux
Instead, the query string looks like this, because it uses URLSearchParams for serialization and the outer object is not flattened:
?params=%5Bobject+Object%5D
What’s the right way to handle this? I know I can pass a custom paramsSerializer, but that function is only passed the parameters, so it can’t reference the explode or style values and produce the correct output. (I also see that those values are the defaults, which makes me wonder whether this is actually a bug.)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have this in my OpenAPI spec:
@rtk-query/openapi-codegen generates what looks like the correct code:
And I call it like this (with React hooks):
I’d expect this to make a request with a query string like this:
Instead, the query string looks like this, because it uses
URLSearchParams
for serialization and the outer object is not flattened:What’s the right way to handle this? I know I can pass a custom
paramsSerializer
, but that function is only passed the parameters, so it can’t reference theexplode
orstyle
values and produce the correct output. (I also see that those values are the defaults, which makes me wonder whether this is actually a bug.)Beta Was this translation helpful? Give feedback.
All reactions