I just copy and paste, change object value and try to trigger errors...but result shows empty array...
please help, give me some clues... i was trapped by this in hours...thank you
----------- terminal info ---------------
[]
import {ValidationSchema, registerSchema, validate} from "class-validator";
export 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);
const user = { firstName: "1", secondName: "1", email: "johnycage.com" };
validate("myUserSchema", user).then(errors => {
console.log(errors)
if (errors.length > 0) {
console.log("Validation failed: ", errors);
} else {
console.log("Validation succeed.");
}
});
UPDATE: "class-validator": "^0.11.1" works but email value had to add constraints: []...
lookes there are something wrong in new release...
back to 0.11.1 now...can anyone here help to fix the bug and build a new release?
I just copy and paste, change object value and try to trigger errors...but result shows empty array...
I'm seeing exactly the same. "v0.11.1" returns array of validation errors, where "v0.12.2" returns empty array.
I've looked through the changelogs for any breaking changes, but couldn't find anything related.
It is related to last big refactor. We do not have tests for schema features so I do not realised we broke this feature completely.
Sorry for that. I will try fix this in short time.
@vlapo is any update on the issue
so I wasted half a day debugging class-validator trying to figure out what AM I doing wrong. You might ask, why didn't I search the open issues instead of wasting that much time? ok, well, who would have thought that any library could fail the most basic scenario? a validation library that can't perform any validation is unheard of.
So, as everyone here, I'm wondering is there's any update on this issue and is this project is still alive?
I understand that open source developers have other responsibilities, but please set the expectations of anyone using your code right.
FYI, soon we I will open a discussion about removing the schema validation functionality at all from class-validator. There are libraries dedicated for that, so we should not roll our own but focus on the decorator based validation.
@NoNameProvided Can you suggest a package which does schema validations (Typescript)
@akshayr-tavisca I use Joi in my current project
@NoNameProvided Is there any update on this issue whether your are going to include it in the future or not.
Also not to mention that current version is broken
Most helpful comment
It is related to last big refactor. We do not have tests for schema features so I do not realised we broke this feature completely.
Sorry for that. I will try fix this in short time.