You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -1111,7 +1110,7 @@ export class UserController {
1111
1110
}
1112
1111
```
1113
1112
1114
-
If `User` is an interface - then simple literal object will be created.
1113
+
If `User` is an interface - then simple literal object will be created.
1115
1114
If its a class - then instance of this class will be created.
1116
1115
1117
1116
This technique works not only with `@Body`, but also with `@Param`, `@QueryParam`, `@BodyParam` and other decorators.
@@ -1121,7 +1120,7 @@ If you want to disable it simply pass `classTransformer: false` to createExpress
1121
1120
1122
1121
## Auto validating action params
1123
1122
1124
-
Sometimes parsing a json object into instance of some class is not enough.
1123
+
Sometimes parsing a json object into instance of some class is not enough.
1125
1124
E.g. `class-transformer` doesn't check whether the property's types are correct, so you can get runtime error if you rely on TypeScript type safe. Also you may want to validate the object to check e.g. whether the password string is long enough or entered e-mail is correct.
1126
1125
1127
1126
It can be done easily thanks to integration with [class-validator][9]. This behaviour is **enabled** by default. If you want to disable it, you need to do it explicitly e.g. by passing `validation: false` option on application bootstrap:
@@ -1141,7 +1140,7 @@ If you want to turn on the validation only for some params, not globally for eve
1141
1140
login(@Body({ validate: true }) user: User) {
1142
1141
```
1143
1142
1144
-
Now you need to define the class which type will be used as type of controller's method param.
1143
+
Now you need to define the class which type will be used as type of controller's method param.
1145
1144
Decorate the properties with appropriate validation decorators.
1146
1145
```typescript
1147
1146
exportclassUser {
@@ -1170,7 +1169,7 @@ export class UserController {
1170
1169
1171
1170
}
1172
1171
```
1173
-
If the param doesn't satisfy the requirements defined by class-validator decorators,
1172
+
If the param doesn't satisfy the requirements defined by class-validator decorators,
1174
1173
an error will be thrown and captured by routing-controller, so the client will receive 400 Bad Request and JSON with nice detailed [Validation errors](https://github.com/pleerock/class-validator#validation-errors) array.
1175
1174
1176
1175
If you need special options for validation (groups, skipping missing properties, etc.) or transforming (groups, excluding prefixes, versions, etc.), you can pass them as global config as `validation` in createExpressServer method or as a local `validate` setting for method parameter - `@Body({ validate: localOptions })`.
0 commit comments