Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[zod-openapi] Can't change style of object query params using extendApi #222

Open
vinicius507 opened this issue Sep 20, 2024 · 0 comments
Open

Comments

@vinicius507
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant