Skip to content

feature: class transformer should strip additional properties #200

@adnan-kamili

Description

@adnan-kamili

As per the doc, a new instance of class is generated by the class-transformer, then why it contains additional properties. For the following post data:

{
    "email": "adnan11@gmail.com",
    "name": "test name",
    "password": "password4",
    "company": "My Company"
}

And following ViewModel:

export class UserViewModel {

    @MaxLength(256)
    name: string;

    @IsEmail()
    email: string;

    @MinLength(6)
    @MaxLength(72)  // bcrypt input limit
    password: string;

    roles: Array<string>
}

The class instance generated for

    @HttpCode(201)
    @Post()
    create( @Body() user: UserViewModel) {
        console.log(user);
        return { message: "created"} ;
    }

is

UserViewModel {
  email: 'adnan11@gmail.com',
  name: 'test name',
  password: 'password4',
  company: 'My Company' }

Where the expected object was:

UserViewModel {
  email: 'adnan11@gmail.com',
  name: 'test name',
  password: 'password4',
  roles: null }

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidIssues with no action to take.type: featureIssues related to new features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions