Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema example in README.md not work #595

Open
LILU-WEB opened this issue Apr 29, 2020 · 4 comments
Open

Schema example in README.md not work #595

LILU-WEB opened this issue Apr 29, 2020 · 4 comments

Comments

@LILU-WEB
Copy link

@LILU-WEB LILU-WEB commented Apr 29, 2020

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 ---------------
[]
Validation succeed.

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.");
    }
});
@LILU-WEB LILU-WEB changed the title Schema example in README.md not working Schema example in README.md not work Apr 29, 2020
@LILU-WEB
Copy link
Author

@LILU-WEB LILU-WEB commented Apr 29, 2020

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?

@devillexio
Copy link

@devillexio devillexio commented Apr 29, 2020

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.

@vlapo
Copy link
Contributor

@vlapo vlapo commented May 4, 2020

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.

@snaerth
Copy link

@snaerth snaerth commented May 29, 2020

@vlapo is any update on the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.