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.

Validate array in Body decorator

See original GitHub issue

Description

Body of type array is not validated.

Minimal code-snippet showcasing the problem

 @Post('/save')
    save( @Body({ type: Hall, validate: true }) halls: Hall[]) { }

Expected behavior

The body should have been validated

Actual behavior

The body is not validated

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
7affercommented, May 27, 2021

Any updates on this?

0reactions
driescroonscommented, Aug 12, 2022

Running into the same issue as @manofteal mentions. When passing an array (which I don’t want), it gets passed to my controller method, unvalidated. Any update on this?

Edit: @attilaorosz I checked your two potential solutions, but shouldn’t we just disable passing arrays as a body? Nest does it that way, because like you mentioned, it’s a TS issue.

  1. https://github.com/nestjs/nest/issues/2874
  2. https://github.com/nestjs/nest/issues/335
Read more comments on GitHub >

github_iconTop Results From Across the Web

NestJs validate array in request body - Stack Overflow
To validate the array, create a dedicated class which contains a property that wraps the array, or use the ParseArrayPipe .
Read more >
NestJS #25 - Decorator Based Validation | Using Class Validator
Decorator -based validation is a technique to validate the incoming request data using the Class- validator package. We can validate data such ...
Read more >
Pipes | NestJS - A progressive Node.js framework
A pipe is a class annotated with the @Injectable() decorator, ... context of validating route parameters, query string parameters and request body values....
Read more >
Validate array in Body decorator - - Bountysource
Javascript Required. Kindly enable Javascript. · Validate array in Body decorator · Description · Expected behavior · Actual behavior · Updates ...
Read more >
Validation - Laravel - The PHP Framework For Web Artisans
Available Validation Rules; Conditionally Adding Rules; Validating Arrays. Validating Nested Array Input ... 'body.required' => 'A message is required',.
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