class-validator
class-validator copied to clipboard
feature: ValidateNested Array is not Working
Description
The decorator IsArray() does not check if the value is array. In my example I need check the arrays allergen and additives in class NutritionalInfoDto.
import {
IsArray,
IsBoolean,
IsIn,
IsNotEmpty,
IsNumber,
IsObject,
IsOptional,
IsString,
Min,
ValidateNested,
} from 'class-validator'
class NutritionalInfoDto {
@IsArray({ message: 'availabilityId precisa ser um array' })
@IsString({
message: 'todos os valores de availabilityId precisam ser uma string!',
each: true,
})
@IsOptional()
allergen: string[];
@IsArray({ message: 'availabilityId precisa ser um array' })
@IsString({
message: 'todos os valores de availabilityId precisam ser uma string!',
each: true,
})
@IsOptional()
additives: string[];
}
export class ProductDto {
@IsObject({ each: true })
@ValidateNested({
each: true,
message: 'wrong values',
})
@Type(() => NutritionalInfoDto)
nutritionalInfo: NutritionalInfoDto;
}
I'm facing the same issue. @IsArray() is not working. @edutucci were you able to solve your problem?