Parameter not marked as optional, when using optional type
paulwer opened this issue · comments
Is there an existing issue for this?
- I have searched the existing issues
Current behavior
I provide an additional parameter to the ApiProperty Decorator, to achieve the right behavior.
@ApiProperty({ required: false }) // isOptional is not reconized by swagger in this case?!
@IsOptional()
@IsObject()
meta?: {
[key: string]: any;
}
Minimum reproduction code
none? but I can provide, if realy needed
Steps to reproduce
- create a DTO with a property with dynamic keys.
- view output of swagger-file
Expected behavior
should detect, that the parameter is optional.
Package version
7.1.16
NestJS version
10.2.10
Node.js version
18.16.1
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
No response
Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).
I found, that this is not related to meta?: { [key: string]: any; } types, and instead is present for all params. Is this a wanted behavior?
This has been discussed several times in the past.
If you want @nestjs/swagger
to automatically detect optional attributes, use CLI plugin (see docs).
Otherwise, we don't take into account ?
as there's no metadata we could rely on (after the transpilation). We do ignore class-validator decorators too (as this is a separate package).