Skip to content

Commit

Permalink
docs: Clarify forbidUnknownValues option
Browse files Browse the repository at this point in the history
  • Loading branch information
roim committed Oct 20, 2021
1 parent 86901ab commit 1e0d1b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export interface ValidatorOptions {
}
```

> It's highly advised to set `forbidUnknownValues: true` as it will prevent unknown objects from passing validation.
> It's highly advised to set `forbidUnknownValues: true` as it will prevent plain javascript objects (eg. `{}`) from passing validation.
## Validation errors

Expand Down
7 changes: 6 additions & 1 deletion src/validation/ValidatorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ export interface ValidatorOptions {
};

/**
* Settings true will cause fail validation of unknown objects.
* Fails validation for objects unknown to class-validator. Defaults to false.
*
* For instance, since a plain empty object has no annotations used for validation:
* - `validate({})` // passes
* - `validate({}, { forbidUnknownValues: true })` // fails.
* - `validate(new SomeAnnotatedEmptyClass(), { forbidUnknownValues: true })` // passes.
*/
forbidUnknownValues?: boolean;

Expand Down

0 comments on commit 1e0d1b0

Please sign in to comment.