class-validator
class-validator copied to clipboard
fix: schema-based validation does not work
Tested with the example from the README - the following validation will always show "Validation succeed". Even in case the object should not pass.
let UserValidationSchema: ValidationSchema = { // using interface here is not required, its just for type-safety
name: "myUserSchema", // this is required, and must be unique
properties: {
firstName: [{
type: "minLength", // validation type. All validation types are listed in ValidationTypes class.
constraints: [2]
}, {
type: "maxLength",
constraints: [20]
}],
lastName: [{
type: "minLength",
constraints: [2]
}, {
type: "maxLength",
constraints: [20]
}],
email: [{
type: "isEmail"
}]
}
};
registerSchema(UserValidationSchema); // if schema is in .json file, then you can simply do registerSchema(require("path-to-schema.json"));
const user = { firstName: "J", secondName: "Cage", email: "johny", some: "thing" };
validate("myUserSchema", user).then(errors => {
if (errors.length > 0) {
console.log("Validation failed: ", errors);
} else {
console.log("Validation succeed.");
}
});
Duplicate of #595.
Schema-based validation will be deprecated in the future probably as a result marking this as low prio.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.