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

ApiProperty containing a key as an array of objects #3041

Open
2 of 4 tasks
abdulkaderelrawas opened this issue Aug 15, 2024 · 3 comments
Open
2 of 4 tasks

ApiProperty containing a key as an array of objects #3041

abdulkaderelrawas opened this issue Aug 15, 2024 · 3 comments

Comments

@abdulkaderelrawas
Copy link

abdulkaderelrawas commented Aug 15, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

This is related to the following issues: 2945, 2418, 1112, 1113, 2418, 735, 90.

I have these 2 classes:

class FilterParamDto {
  @IsString()
  filterBy: string;

  @IsString()
  operator: string;

  @IsString()
  value: string;
}

export class SortAndFilterDto extends SortParamsDto {
  @ApiProperty({ type: FilterDto, isArray: true })
  readonly filters: FilterParamDto[];
}

I am getting this

image

I tried the following:

  • plugin in nest cli and added all the necessary decorators to filters and not use the @ApiProperty: doesn't work.
  • @ApiProperty({ type: [FilterDto]}) instead of @ApiProperty({ type: FilterDto, isArray: true }): doesn't work.
  • changed the type of FilterDto to get an array of strings: works

So I figured the problem is somewhere in reading array of objects only.

I read some workarounds using $ref and @apiquery over the controller directly, but it doesn't make sense to do workarounds that will disorganize the code when there might be a bug that needs fixing.

Minimum reproduction code

Reproduction repo

Steps to reproduce

No response

Expected behavior

the expected behaviour should be like the image

image

Package version

7.4.0

NestJS version

9.4.3

Node.js version

20.11.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

This has been reported in more than 5 other issues since 2018, is there anything we can do to fix? there is even an open PR

@kamilmysliwiec
Copy link
Member

Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).

@abdulkaderelrawas
Copy link
Author

abdulkaderelrawas commented Aug 15, 2024

@kamilmysliwiec

here's a minimal repro

Reproduction Repo

how to setup

  1. clone
  2. npm/yarn/pnpm i
  3. pnpm start:dev
  4. go to http://localhost:3000/docs
  5. go to app -> bug endpoint
  6. try it out
  7. there is no filters array of objects

can we return it to (bug)(needs triage) instead of (needs clarification)? thank you :)

Things to play with:

  • I added class-validator, class-transformer and @nestjs/swagger
  • I added the plugin in the nestjs cli
  • I added @ApiProperty to all api properties
  • I added validations in the query dto

@abdulkaderelrawas
Copy link
Author

Ping

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