ApiProperty containing a key as an array of objects
Is there an existing issue for this?
- [X] 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
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
FilterDtoto 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
Steps to reproduce
No response
Expected behavior
the expected behaviour should be like the 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
- [X] 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
Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).
@kamilmysliwiec
here's a minimal repro
how to setup
- clone
- npm/yarn/pnpm i
- pnpm start:dev
- go to http://localhost:3000/docs
- go to app -> bug endpoint
- try it out
- 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-transformerand@nestjs/swagger - I added the plugin in the nestjs cli
- I added
@ApiPropertyto all api properties - I added validations in the query dto
Ping
https://github.com/nestjs/swagger/pull/1113