MichalLytek / class-transformer-validator

A simple plugin for class-transformer and class-validator which combines them in a nice and programmer-friendly API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple custom validators

opened this issue · comments

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?

Please ask on class-validator GitHub repository 😉