Closed
Description
Description
How to perform a oneOf
validation of a nested object i.e., child object is either of TypeA
or TypeB
? This seems like a very common use case, is there an out-of-the-box solution for this? I understand that this problem is concerning class-transformer
more than it is class-validator
..
Is there an example of a generic @OneOf()
decorator? Any ideas on how to work with class-transformer
and class-validator
together to make this happen?
Reproduction
class TypeA {
@IsString()
public foo;
}
class TypeB {
@IsString()
public bar;
}
class Parent {
@IsObject()
@ValidateNested()
@Type((): Function => TypeA) // ???
public child: TypeA | TypeB;
}
Environment
- nodejs: 8.11.2
- browser
- framework/library
class-validator version: 0.12.2