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: @ValidateNested not working #1129

Open
AdmanDev opened this issue Apr 28, 2023 · 2 comments
Open

fix: @ValidateNested not working #1129

AdmanDev opened this issue Apr 28, 2023 · 2 comments
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.

Comments

@AdmanDev
Copy link

AdmanDev commented Apr 28, 2023

Description

Hello, I have a problem with @ValidateNested decorator. It is not working for me; I have tried with a single object and an array, but neither is working.

Minimal code-snippet showcasing the problem

export class CreateEventRequest {

	@ValidateNested({ each: true })
	public polls: CreatePollRequest[] = []

	@ValidateNested()
	public singlePoll: CreatePollRequest = new CreatePollRequest()
}

export class CreatePollRequest {
       ....
	@IsString({ message: "La question du sondage est requise !" })
	@IsNotEmpty({ message: "La question du sondage est requise !" })
	public question = ""

	@IsArray({ message: "Les options du sondage sont requises !" })
	@IsString({
		each: true,
		message: "Les options du sondage sont requises !"
	})
	@IsNotEmpty({
		each: true,
		message: "Une option est vide !"
	})
	@ArrayMinSize(2, { message: "Le sondage doit avoir au moins 2 options !" })
	public options: string[] = []
}

Expected behavior

I sent this body param with a bad value for "question" field

{
...
    "polls": [
        {
            "question": 1 // should be a string,
            "options": ["Le légendaire", "La tête dans les nuage"]
        }
    ],
    "singlePoll": {
            "question": 1 // should be a string,
            "options": ["Le légendaire", "La tête dans les nuage"]
    }
}

Actual behavior

The "polls" and "singlePoll" are not validated and the request will pass.
But an error should be thrown.

My package.json

{
   ...,
   "reflect-metadata": "^0.1.13",
    "routing-controllers": "^0.10.2",
    "typedi": "^0.10.0"
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
}

The issue #483 is similar to my problem but there is no solution

Have you any solution ?

(Sorry for my english, I am french ^^)

@AdmanDev AdmanDev added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Apr 28, 2023
@AdmanDev AdmanDev changed the title fix: @ValidateNested fix: @ValidateNested not working Apr 28, 2023
@attilaorosz
Copy link
Member

@AdmanDev this seems like an issue in class-validator rather than routing-controllers. Could you post this issue in that repo?

@AdmanDev
Copy link
Author

okey @attilaorosz

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

2 participants