Skip to content

question: ValidateNested with IsOptional throws a BadRequest #577

@Jhonnyc

Description

@Jhonnyc

Currently using -

  • class-transformer - 0.2.3
  • class-validator - 0.11.0
  • express - 4.15.4
  • node version - 13.9.0

I have 2 classes -

export class A {
    @IsNotEmpty()
    @Length(2, 32)
    public someField: string;

    @IsOptional()
    @IsEnum(EnumClass)
    public someEnum: EnumClass;
}
export class B {
    @ValidateNested({ each: true })
    @Type(() => A)
    public arrayOfAs: A[];
}

For some reason - I get a BadRequest when I don't send the enum type although it's decorated with "IsOptional", am I doing something wrong or is that a bug? Couldn't find any sample of code to validate a nested object array with isOptional decoraror.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: questionQuestions about the usage of the library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions