Skip to content

@ValidateNested doesn't respect @ValidateIf #2599

Open
@adi-doorloop

Description

@adi-doorloop

I'm staggered by how unintuitive this library is, time and again.

I have the following DTO:

class FormDto {
  @IsNotEmpty()
  @IsBoolean()
  enabled: boolean

  @ValidateIf((dto) => dto.enabled)
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => UserDto)
  users?: UserDto[];
}

When providing an invalid users array to the users field, I'm getting a validation error even though the enabled field is set to false. Why?? I'm fine with submitting an invalid field when the flag is false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs triageIssues which needs to be reproduced to be verified report.type: fixIssues describing a broken feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions