Description
When using an object as query parameter the generated function set the querySerialiazer parameter and this overrides the one set in the client with client.setConfig.
Parameter schema:
{
"\/products":{
"get":{
"operationId":"ListProducts",
"tags":[
"Product"
],
"parameters":[
{
"name":"filter",
"in":"query",
"schema":{
"type":"object",
"properties":{
"q":{
"type":"string",
"description":"Search query"
}
}
}
}
]
}
}
}
Generated code:
export const listProducts = <ThrowOnError extends boolean = false>(
options?: Options<ListProductsData, ThrowOnError>,
) =>
(options?.client ?? client).get<
ListProductsResponses,
ListProductsErrors,
ThrowOnError
>({
querySerializer: { parameters: { filter: { object: { style: "form" } } } },
url: "/products",
...options,
});
I didn't find a configuration option to disable this behaviour. I just want to handle the querySerialization globally in the client, so I propose to resolve this by adding a new config option to disable the generation of querySerializer from the schema. I think this is the relevant code that generate this:
|
const paramSerializers = $.object(); |
|
|
|
for (const name in operation.parameters?.query) { |
|
const parameter = operation.parameters.query[name]!; |
|
|
|
if (parameter.schema.type === 'array' || parameter.schema.type === 'tuple') { |
|
if (parameter.style !== 'form' || !parameter.explode) { |
|
// override the default settings for array serialization |
|
paramSerializers.prop( |
|
parameter.name, |
|
$.object().prop( |
|
'array', |
|
$.object() |
|
.$if(parameter.explode === false, (o) => |
|
o.prop('explode', $.literal(parameter.explode)), |
|
) |
|
.$if(parameter.style !== 'form', (o) => o.prop('style', $.literal(parameter.style))), |
|
), |
|
); |
|
} |
|
} else if (parameter.schema.type === 'object') { |
|
if (parameter.style !== 'deepObject' || !parameter.explode) { |
|
// override the default settings for object serialization |
|
paramSerializers.prop( |
|
parameter.name, |
|
$.object().prop( |
|
'object', |
|
$.object() |
|
.$if(parameter.explode === false, (o) => |
|
o.prop('explode', $.literal(parameter.explode)), |
|
) |
|
.$if(parameter.style !== 'deepObject', (o) => |
|
o.prop('style', $.literal(parameter.style)), |
|
), |
|
), |
|
); |
|
} |
|
} |
|
} |
|
|
|
if (paramSerializers.hasProps()) { |
|
// TODO: if all parameters have the same serialization, |
|
// apply it globally to reduce output size |
|
reqOptions.prop('querySerializer', $.object().prop('parameters', paramSerializers)); |
|
} |
Reproducible example or configuration
No response
OpenAPI specification (optional)
No response
System information (optional)
No response
Description
When using an object as query parameter the generated function set the
querySerialiazerparameter and this overrides the one set in the client withclient.setConfig.Parameter schema:
{ "\/products":{ "get":{ "operationId":"ListProducts", "tags":[ "Product" ], "parameters":[ { "name":"filter", "in":"query", "schema":{ "type":"object", "properties":{ "q":{ "type":"string", "description":"Search query" } } } } ] } } }Generated code:
I didn't find a configuration option to disable this behaviour. I just want to handle the querySerialization globally in the client, so I propose to resolve this by adding a new config option to disable the generation of
querySerializerfrom the schema. I think this is the relevant code that generate this:openapi-ts/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts
Lines 290 to 334 in 663e270
Reproducible example or configuration
No response
OpenAPI specification (optional)
No response
System information (optional)
No response