Skip to content

fix: class-validator does not work on last version of RC #1204

Open
@cellezam

Description

@cellezam

Description

Using the latest version of routing-controller, it seems that input validation is not working anymore. Here is my code and my setup

Minimal code-snippet showcasing the problem

export class GenerateIdentificationByEmailCommand {

  @Expose()
  @IsEmail()
  email: string;

  static setProperties(cmd: GenerateIdentificationByEmailCommand):  GenerateIdentificationByEmailCommand {
    return plainToClass( GenerateIdentificationByEmailCommand, cmd, { excludeExtraneousValues: true });
  }
}

@Post('/email')
  async generateIdentificationByEmail(
    @Res() res: Response,
    @Body({validate: true}) cmd: GenerateIdentificationByEmailCommand
  ) {
    const body = GenerateIdentificationByEmailCommand.setProperties(cmd);
    const result = await this._generateIdentification.execute({
      provider: {
        mode: AuthMode.BASIC,
        email: body.email,
      }
    })
    return res.status(201).send(result);
  }
  
  useExpressServer(app, {
    defaultErrorHandler: true,
    defaults: {
      nullResultCode: 400,
      undefinedResultCode: 204,
      paramOptions: {
        required: true,
      },
    },
    classTransformer: true,
    validation: true,
    routePrefix: "/oks",
    controllers: [
      UserController,
      CompanyController,
      MentorController,
      CommonController,
    ],
  });
 

Expected behavior

I expect when request api endpoint to throw if input validation failed

Actual behavior

It does not throw when i made http request. It returns a 201 response.

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