I'm trying to validate an array of objects. I tried the method mentioned here and that works fine for most cases. But the issue I'm facing is that when the array contains another array, the validation does not throw an error. While sending an array with a string the error displayed is must be either object or array
. So I suppose it accepts an array. How do I stop it from letting through an array of arrays? I need it to only accept objects.
valid
{
"user" : [{ "name" : "kate"}, {"name":"mike"}]
}
should be invalid
{
"user" : [[]]
}
My validation code
export class UserInfo {
@ApiProperty({ required: true })
@IsNotEmpty()
@IsString()
name: string;
}
export class User {
@IsOptional()
@IsArray()
@ArrayMinSize(1)
@ValidateNested()
@Type(() => UserInfo)
user: UserInfo;
}