redux-toolkit
redux-toolkit copied to clipboard
Support DeepObject query parameters in codegen
I'm attempting to describe query parameters such as /tasks?page[size]=1&page[number]=1
, which is done according to the OpenAPI spec using style: deepObject
and explode: true
. See: https://swagger.io/docs/specification/serialization/
The codegen 'works' in that there are no errors. I'm able to pass an object in the hook:
useGetTasksQuery({page: {size: 1, number: 1}})
However, it turns into this in the URL: /tasks?page=[object+Object]
.
Here's my open api spec for the parameter:
---
name: page
in: query
required: false
description: 'In a list return, the data associated with the page number and size returned.'
explode: true
style: deepObject
schema:
type: object
properties:
number:
type: number
description: The page to jump to
size:
type: number
description: The number of resources returned per page.
Is this supported, and if not is it easily added?
Thanks!
Would it be using the code in here?
https://github.com/reduxjs/redux-toolkit/blob/master/packages/toolkit/src/query/defaultSerializeQueryArgs.ts
(Not affected by the issue, just curious)
It looks like that may be the code, yes.
EDIT: Acutally, that looks like the code to serialize the key in subscriptions, which works correctly. It's just when constructing the URL.
defaultSerializeQueryArgs
seems to be for generating cache keys. Query parameters are serialized by paramsSerializer
of fetchBaseQuery
:
A function that can be used to apply custom transformations to the data passed into params. If you don't provide this, params will be given directly to new URLSearchParams(). With some API integrations, you may need to leverage this to use something like the query-string library to support different array types.
https://github.com/reduxjs/redux-toolkit/issues/3640#issuecomment-1837894377