question: accept only objects of a given validate-required form within an array
See original GitHub issueI 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:
- Created a year ago
- Reactions:2
- Comments:8 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I still think there is a legitimate issue here. It doesn’t seem intuitive or practical that
ValidateNested
accepts empty arrays.I think the issue is twofold:
ValidateNested
. There should at least be an option to disable that behaviour or something.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})