Skip to content

Commit 1ed3925

Browse files
Merge pull request #2807 from KarthikRaju391/patch-1
docs(cli-plugin.md): Clarify role of Swagger plugin and class-validator in validation.
2 parents 1c0e18e + c00d687 commit 1ed3925

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

content/openapi/cli-plugin.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export class CreateUserDto {
5353
}
5454
```
5555

56+
> info **Note** The Swagger plugin will derive the @ApiProperty() annotations from the TypeScript types and class-validator decorators. This helps in clearly describing your API for the generated Swagger UI documentation. However, the validation at runtime would still be handled by class-validator decorators. So, it is required to continue using validators like `IsEmail()`, `IsNumber()`, etc.
57+
58+
Hence, if you intend to relay on automatic annotations for generating documentations and still wish for runtime validations, then the class-validator decorators are still necessary.
59+
5660
> info **Hint** When using [mapped types utilities](https://docs.nestjs.com/openapi/mapped-types) (like `PartialType`) in DTOs import them from `@nestjs/swagger` instead of `@nestjs/mapped-types` for the plugin to pick up the schema.
5761
5862
The plugin adds appropriate decorators on the fly based on the **Abstract Syntax Tree**. Thus you won't have to struggle with `@ApiProperty` decorators scattered throughout the code.

0 commit comments

Comments
 (0)