swagger icon indicating copy to clipboard operation
swagger copied to clipboard

classValidatorShim ignores class-validator decorators

Open its-dibo opened this issue 2 years ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current behavior

decorators from class-validator are ignored by Nest

Minimum reproduction code

.

Steps to reproduce

1- add the plugin and enable classValidatorShim

   "plugins": [
      {
        "name": "@nestjs/swagger",
        "options": {
          "introspectComments": true,
          "classValidatorShim": true
        }
      }
    ]

2- create an entity, and attach @IsEmail() to a property

@Entity()
class Users{
  @Column({ unique: true })
  @IsMobilePhone()
  @Matches(/^\+/)
  mobile: string;
}

3- open swagger and create a new user (via a POST request) and perform an intented violations for the email field. no one of the attached decorators from class-validation is working only unique is considered by TypeORM

Expected behavior

the email violations are catched

Package version

7.1.14

NestJS version

10

Node.js version

20

In which operating systems have you tested?

  • [ ] macOS
  • [ ] Windows
  • [X] Linux

Other

No response

its-dibo avatar Nov 09 '23 09:11 its-dibo

Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).

why reproductions are required

jmcdo29 avatar Nov 09 '23 15:11 jmcdo29