[zod-openapi] Can't change style of object query params using extendApi
Opened this issue · 0 comments
vinicius507 commented
Greetings,
I'm trying to use @anatine/zed-openapi
alongside @anatine/zed-nestjs
to create a Dto for a query parameter as such:
const findManyUsersFilterSchema = extendApi(
z.strictObject({
name: z.string(),
email: z.string().email()
}),
{
title: 'Find Many Users Query Filters',
description: 'The filters to apply when finding many users'
}
)
export class FindManyUsersFilterDto extends createZodDto(findManyUsersFilterSchema) {}
Example usage:
// [...]
@Get()
@ApiOperation({ summary: 'Lists users' })
@ApiOkResponse({
type: PaginatedUsersResponseDto,
description: 'List os users returned.'
})
async listUsers(@Query('filters') params: FindManyUsersFilterDto) {
// Redacted
}
This Dto is meant to be used for validating a query parameter, but when I try to execute the request via the Swagger UI, it serializes the parameters in a unexpected way.
Expected: /users?filters[name]=foo&filters[email]=bar
Actual: /users?name=foo&email=bar
I understand that, using the @ApiQuery
decorator from @nestjs/swagger
, I can change the style of the query params serialization to 'deepObject', but I can't seem to do so using @anatine/zod-openapi
. Is there any way to do so currently?