class-validator
Advanced tools
Comparing version 0.8.3 to 0.8.4
{ | ||
"name": "class-validator", | ||
"private": false, | ||
"version": "0.8.3", | ||
"version": "0.8.4", | ||
"description": "Class-based validation with Typescript / ES6 / ES5 using decorators or validation schemas. Supports both node.js and browser", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -123,2 +123,25 @@ # class-validator | ||
### Passing options | ||
The `validate` function optionally expects a `ValidatorOptions` object as a second parameter. | ||
```ts | ||
export interface ValidatorOptions { | ||
skipMissingProperties?: boolean; | ||
whitelist?: boolean; | ||
forbidNonWhitelisted?: boolean; | ||
groups?: string[]; | ||
dismissDefaultMessages?: boolean; | ||
validationError?: { | ||
target?: boolean; | ||
value?: boolean; | ||
}; | ||
forbidUnknownValues?: boolean; | ||
} | ||
``` | ||
> It's highly advised to enable on `forbidUnknownValues` what prevent unknown objects to pass validation. | ||
## Validation errors | ||
@@ -125,0 +148,0 @@ |
@@ -36,2 +36,16 @@ "use strict"; | ||
var groupedMetadatas = this.metadataStorage.groupByPropertyName(targetMetadatas); | ||
if (this.validatorOptions && this.validatorOptions.forbidUnknownValues && !targetMetadatas.length) { | ||
var validationError = new ValidationError_1.ValidationError(); | ||
if (!this.validatorOptions || | ||
!this.validatorOptions.validationError || | ||
this.validatorOptions.validationError.target === undefined || | ||
this.validatorOptions.validationError.target === true) | ||
validationError.target = object; | ||
validationError.value = undefined; | ||
validationError.property = undefined; | ||
validationError.children = []; | ||
validationError.constraints = { unknownValue: "an unknown value was passed to the validate function" }; | ||
validationErrors.push(validationError); | ||
return; | ||
} | ||
if (this.validatorOptions && this.validatorOptions.whitelist) | ||
@@ -38,0 +52,0 @@ this.whitelist(object, groupedMetadatas, validationErrors); |
@@ -41,2 +41,6 @@ /** | ||
}; | ||
/** | ||
* Settings true will cause fail validation of unknown objects. | ||
*/ | ||
forbidUnknownValues?: boolean; | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
427318
4127
950