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

Wrong swagger generation for @Query with array of objects #2945

Open
2 of 4 tasks
wilker7ribeiro opened this issue May 9, 2024 · 1 comment
Open
2 of 4 tasks

Wrong swagger generation for @Query with array of objects #2945

wilker7ribeiro opened this issue May 9, 2024 · 1 comment

Comments

@wilker7ribeiro
Copy link

wilker7ribeiro commented May 9, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

I want to create a GET endpoint with a inner object inside query params:

export class QueryParamsSubObject {
  @ApiProperty()
  subObjectStringParam: string;
}

export class QueryParams {
  @ApiProperty()
  stringParam: string;

  @ApiProperty({ type: QueryParamsSubObject })
  subObject: QueryParamsSubObject;
}

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get('/bugged')
  getHelloBugged(@Query() queryParams: QueryParams): string {
    console.log(queryParams);
    return this.appService.getHello();
  }
}

The swagger definition is bugged, having all parameters from QueryParamsSubObject inside QueryParams instead of QueryParams.subObject:

image

The definition is generated correctly when using @ApiQuery instead of @Query:

@Get('/correct')
@ApiQuery({
  type: QueryParams,
})
getCorrectlyGenerated(): string {
  return this.appService.getHello();
}

image

Minimum reproduction code

Codesandbox
https://github.com/wilker7ribeiro/nest-swagger-query-object-param-issue

Steps to reproduce

  1. npm install
  2. npm start
  3. open http://localhost:3000/api

Expected behavior

@Query should correctly generate the swagger definition as @ApiQuery does.

Package version

7.3.1

NestJS version

10.3.2

Node.js version

10.3.2

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux
@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this issue?

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

No branches or pull requests

2 participants