question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

question: accept only objects of a given validate-required form within an array

See original GitHub issue

I was trying to… Allow only an array of objects to be passed on a given property

The problem: ValidateNested allows both objects and arrays, making it possible to pass any amounts of nested arrays as long as in any moment where there’s any other type defined within the matrixes it is according to the other constrains.

@ArrayMinSize(0)
@ArrayMaxSize(5)
@ValidateNested({ each: true })
@Type(() => OfferPricingDTO)
pricing: OfferPricingDTO[];
// allows [[[]]], where my interest is to only allow objects with the passed type as direct items of this property.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
braaarcommented, Aug 30, 2022

I still think there is a legitimate issue here. It doesn’t seem intuitive or practical that ValidateNested accepts empty arrays.

1reaction
braaarcommented, Aug 30, 2022

I think the issue is twofold:

  1. It’s not nice that empty arrays are accepted by ValidateNested. There should at least be an option to disable that behaviour or something.
  2. It would be nice to have a simple way to tell class-validator to validate an object property of a specific class, similar to @IsEnum(entity: object). For example, it could look like this: @ValidateNested(OfferPricingDTO, {each: true})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Validate an array of integers - laravel
Your validation as written should work. If the exists validation is used with an array, it will automatically use where in for the...
Read more >
Chp 6 Flashcards
Study with Quizlet and memorize flashcards containing terms like True, True, true and more.
Read more >
Validation - Laravel - The PHP Framework For Web Artisans
This object exposes only , except , and all methods to retrieve a subset of the validated data or the entire array of...
Read more >
Validation
Form -level validation is useful because you have complete access to all of your form's values and props whenever the function runs, so...
Read more >
How to Create Array of Objects in Java?
For example, if you have a class Student, and we want to declare and instantiate an array of Student objects with two objects/object...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found