nestjs / swagger

OpenAPI (Swagger) module for Nest framework (node.js) :earth_americas:
https://nestjs.com
MIT License
1.69k stars 475 forks source link

classValidatorShim ignores class-validator decorators #2698

Closed its-dibo closed 7 months ago

its-dibo commented 1 year ago

Is there an existing issue for this?

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?

Other

No response

jmcdo29 commented 1 year ago

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

why reproductions are required