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

Support class-validator 0.12.x #2

Open
nolazybits opened this issue May 29, 2020 · 9 comments
Open

Support class-validator 0.12.x #2

nolazybits opened this issue May 29, 2020 · 9 comments
Labels
enhancement New feature or request

Comments

@nolazybits
Copy link

I really like the fact you are leveraging existing class-validator.
I've been trying to have data generated for a model like this for instance

import { Fixture } from "class-fixtures-factory";
import { IsString } from "class-validator";

export abstract class ITest
{
    @IsString()
    public abstract name: string;

    @Fixture()
    public abstract age: number;
}

Sadly the name property is not generated. Only the one with the Fixture decorator.
Would you have a working example somewhere I could look at or is this a bug?

Do I need to map the class-validator metadataStore to the one used by this library at all?

Thanks for the library!

@CyriacBr
Copy link
Owner

CyriacBr commented May 29, 2020

Hello.
I actually forgot to support some of the basic class-validator decorators such as IsString. I just pushed an update (1.4.0) and that should work for now, thanks for letting me know!

However, keep in mind that I was wondering about a more efficient way to handle third-party decorators, so there may be missing support for some other decorators too. Feel free to let me know if there are other decorators from class-validator I should support.

Also I updated the README so you should read it again.

@nolazybits
Copy link
Author

Thank you much for the fast answer.
I'll keep you posted and happy to create PRs too!
Thanks again.

@nolazybits
Copy link
Author

I'm sorry but this same example is still not working with the new released version.

@nolazybits
Copy link
Author

One thing is class-validator has been updated to 0.12.x where changes were introduce to the metadata store and how to get it. That might be the why? Would be good to add version range in your package.json on the class-validator 0.11.x and maybe (please) have a 1.5 version supporting class-validator >= 0.12.x

Thanks a lot!

@CyriacBr
Copy link
Owner

Yeah I updated class-validator and my tests break now. I'll have to look into that.
Thank you.

@CyriacBr CyriacBr reopened this May 30, 2020
@CyriacBr CyriacBr changed the title Example of using it with class-validator and DI (if required) Support class-validator 0.12.x May 30, 2020
@CyriacBr
Copy link
Owner

CyriacBr commented May 30, 2020

So, it appears that since the 0.12 version, the decorators names are lost when stored. I opened an issue there.

So, unless they fix that, there'd be no way to know which decorators are used in your classes. So if you want to use class-fixtures-factory, you'd have to rollback to 0.11.x version. I'll add a disclaimer in the README.

@nolazybits
Copy link
Author

I hope they'll fix this in class-validator🤞
Thanks again @CyriacBr for being so reactive 👍

@nolazybits
Copy link
Author

nolazybits commented Dec 7, 2020

@CyriacBr we have forked class-validator here
https://github.com/ts-revival/class-validator and merged some of the required PR to have this lib working post 0.12.0 again.

if you could provide maybe a version that uses @ts-revival/class-validator so we can start moving forward that would be awesome!

Thanks for this awesome lib again

@CyriacBr
Copy link
Owner

CyriacBr commented Jan 5, 2021

Hi @nolazybits . Sorry for the late reply, was kinda busy.
I'm going to look into a new release for this package next weekend so hopefully I'll see how to integrate your fix.

@CyriacBr CyriacBr added the enhancement New feature or request label Jan 5, 2021
@CyriacBr CyriacBr modified the milestone: Next release Jan 5, 2021
@CyriacBr CyriacBr mentioned this issue Apr 12, 2021
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants