MichalLytek / class-transformer-validator

A simple plugin for class-transformer and class-validator which combines them in a nice and programmer-friendly API.
MIT License
200 stars 19 forks source link

Simple custom validators #33

Closed ghost closed 3 years ago

ghost commented 3 years ago

I don't understand why creating custom validators need require so much boilerplate with class creation etc. Surely there should be a simple way to create custom validators that take messages? E.g.

@IsString
@IsNotEmpty
@ValidIf(o.section === "SomeSectionName", { message: "Wrong section" })
myProperty!: string

Am I missing a simple way of doing this without creating a constraint class and then registering a decorator or using the @Validate(MyConstraint, { message: "Wrong section" }) form?

MichalLytek commented 3 years ago

Please ask on class-validator GitHub repository 😉