Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: class-validators and nest.js: Global custom validator with imports from two different modules is only triggered in one of the two modules #2320

Open
SakisTsalk opened this issue Nov 27, 2023 · 0 comments
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.

Comments

@SakisTsalk
Copy link

SakisTsalk commented Nov 27, 2023

Description

I am using Nest.js and class-validator. If the same validator is being used in two different modules, and Dto Objects from both of the modules are being used inside the validator, the validator only triggers in one of the two modules. Main suspect is a circural dependency.

Minimal code-snippet showcasing the problem
https://github.com/SakisTsalk/nestjs-custom-validators-issue
Steps to reproduce:

  1. install dependencies and start application
    yarn install
    yarn start:dev
  2. Make two POST requests
    curl --location 'http://localhost:3000/dogs/create' \ --header 'Content-Type: application/json' \ --data '{ "dog": { "name": "rex" } }'
    curl --location 'http://localhost:3000/cats/create' \ --header 'Content-Type: application/json' \ --data '{ "cat": { "name": "kittie" } }'

Expected behavior

I would expect that an error is thrown during build time or at least when the validator is triggered.

Actual behavior

No error is thrown the validator works correctly in one of the modules, but is completely ignored from the other module

Same issue reported in nest.js side:
nestjs/nest#12847

@SakisTsalk SakisTsalk added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.
Development

No branches or pull requests

1 participant