Skip to content

question: Inheriting feature does not work as i expect, whenever i activate the whitelist #1288

@kasir-barati

Description

@kasir-barati

I was trying to use whitelist alongside the inheriting
I have a dto, this dto would be used whenever the common user trys to create a user:

class CreateUserDto {
  @IsString()
  name: string;
}

And admin can create user too, but admin can specify more fields:

class AdminCreateUserDto extends CreateUserDto {
  @IsNumber()
  credit: number;
}

now In the controller I have:

// first scenario: disabled whaitelist
async adminCreateUser(@Body({ validate: { whitelist: false } }) user: AdminCreateUserDto) {
  /*
   * POST /users
   * body: { name: "nodejs", credit: 1000 }
   */
  console.log(user); // { name: "nodejs", credit: 1000 }
}
 
// second scenario: acvtived whitelist
async adminCreateUser(@Body({ validate: { whitelist: true } }) user: AdminCreateUserDto) {
  /*
   * POST /users
   * body: { name: "as", credit: 1000 }
   */
  console.log(user); // { credit: 1000 }
}

The problem:
As you can see I do not have the name field. My expectation is to get the same result in the second scenario.

  • Node: v14.17.6
  • npm: 6.14.15
  • class-validator: ^0.13.1

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