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

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

Schema example in README.md not work #595

LILU-WEB opened this issue Apr 29, 2020 · 17 comments
Labels
status: wontfix type: fix Issues describing a broken feature.

Comments

@LILU-WEB
Copy link

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

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?

@devilleweppenaar
Copy link

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 vlapo added type: fix Issues describing a broken feature. priority: high labels Apr 29, 2020
@vlapo
Copy link
Contributor

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 commented May 29, 2020

@vlapo is any update on the issue

@aabuelenin
Copy link

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.

@NoNameProvided
Copy link
Member

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.

@akshayr-tavisca
Copy link

@NoNameProvided Can you suggest a package which does schema validations (Typescript)

@Varkal
Copy link

Varkal commented Nov 6, 2020

@akshayr-tavisca I use Joi in my current project

@snaerth
Copy link

snaerth commented Dec 14, 2020

@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

@BenjD90
Copy link

BenjD90 commented Apr 1, 2021

The feature, schema based validation, is broken since the PR #568 , we can easily see that it was a bit known with those changes : https://github.com/typestack/class-validator/pull/568/files#diff-8ad828b3cb077e586ecc20d38c15cd197e1efc9bf537cb8c985b845b63d97138L16

😢

@whmori17
Copy link

Hi guys! How's the issue going? There's something we can do to help?

@Gbuomprisco
Copy link

Why not at least update the README and say "Don't even try"? Also spent a whole day debugging this :|

@J-Zet
Copy link

J-Zet commented Oct 5, 2022

Hi guys! Any update on this, about 2.5 years later?

@braaar
Copy link
Member

braaar commented Oct 6, 2022

Thanks for bumping this (I had no idea this features was broken), but this issue will probably not see a lot of action in the near future, as we have quite low maintainer activity and no way to add more maintainers. See #1719

@braaar
Copy link
Member

braaar commented Oct 6, 2022

I agree with @NoNameProvided here. This feature seems like a tacked on afterthought to me.

For schema based validation, I would recommend zod.

Duplicate of this issue: #1155

@NoNameProvided
Copy link
Member

As mentioned in the thread, schema-based validation is deprecated and will be removed. The documentation has been updated, it now contains a suggestion of what libraries to use instead of class-validator.

To clarify, class-validatior will retain the ability to serialize validation meta-data and send it over the wire, but it will be considered an internal API and one must define their "validation schema" with decorators first.

I am closing this issue as wontfix.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: wontfix type: fix Issues describing a broken feature.
Development

Successfully merging a pull request may close this issue.