diff --git a/src/validation/ValidationExecutor.ts b/src/validation/ValidationExecutor.ts index 36e63d0f2f..cca42dbf95 100644 --- a/src/validation/ValidationExecutor.ts +++ b/src/validation/ValidationExecutor.ts @@ -168,6 +168,7 @@ export class ValidationExecutor { // handle IS_DEFINED validation type the special way - it should work no matter skipUndefinedProperties/skipMissingProperties is set or not this.defaultValidations(object, value, definedMetadatas, validationError.constraints); + this.mapContexts(object, value, definedMetadatas, validationError); if (value === undefined && this.validatorOptions && this.validatorOptions.skipUndefinedProperties === true) { return; @@ -186,6 +187,7 @@ export class ValidationExecutor { this.nestedValidations(value, nestedValidationMetadatas, validationError.children); this.mapContexts(object, value, metadatas, validationError); + this.mapContexts(object, value, customValidationMetadatas, validationError); } private generateValidationError(object: Object, value: any, propertyName: string) { diff --git a/test/functional/validation-options.spec.ts b/test/functional/validation-options.spec.ts index 7ef61206bd..394718749e 100644 --- a/test/functional/validation-options.spec.ts +++ b/test/functional/validation-options.spec.ts @@ -1,5 +1,5 @@ import "es6-shim"; -import {Contains, Matches, MinLength, ValidateNested, ValidatorConstraint, Validate } from "../../src/decorator/decorators"; +import {Contains, IsDefined, Matches, MinLength, ValidateNested, ValidatorConstraint, Validate } from "../../src/decorator/decorators"; import {Validator} from "../../src/validation/Validator"; import {ValidationError, ValidatorConstraintInterface} from "../../src"; @@ -953,14 +953,21 @@ describe("validation options", function() { } }) someOtherProperty: string; + + @IsDefined({ + context: { + foo: "bar" + } + }) + requiredProperty: string; } const model = new MyClass(); - // model.someProperty = "hell no world"; return validator.validate(model).then(errors => { - errors.length.should.be.equal(2); + errors.length.should.be.equal(3); errors[0].contexts["contains"].should.be.eql({ hi: "there" }); errors[1].contexts["contains"].should.be.eql({ bye: "now" }); + errors[2].contexts["isDefined"].should.be.eql({ foo: "bar" }); }); });