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.

ValidateNested without decorator is not working

See original GitHub issue

Let’s say we have the following validation schema:

// this will not work
export const taskValidationSchema: ValidationSchema = {
  name: 'TaskValidationSchema',
  properties: {
    'title': [
      {
        type: 'minLength',
        constraints: [3],
        groups: ['admin'],
      }
    ],
    'files': [
      {
        type: 'nestedValidation',
        each: true,
        groups: ['admin'],
      }
    ]
  }
};

Validator is not aware of which validation schema to use for the nested property.

Here is my solution:

export const taskValidationSchema: ValidationSchema = {
  name: 'TaskValidationSchema',
  properties: {
    'title': [
      {
        type: 'minLength',
        constraints: [3],
        groups: ['admin'],
      }
    ],
    'files': [
      {
        type: 'nestedValidation',
        options: {'validationSchema': 'TaskFileValidationSchema'},
        each: true,
        groups: ['admin'],
      }
    ]
  }
};

Would you accept PR?

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
enrico-calzavaracommented, Jul 12, 2018

@NoNameProvided any news on this?

1reaction
NoNameProvidedcommented, Nov 4, 2018

@rlataguerra please open a different issue for your issue explaining the details and providing a small example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Class-validator ignores ValidateNested objects - Stack Overflow
As the documentation says, the validated property must be a Class instance so the validation decorator will work. So, the solution for this ......
Read more >
typestack/class-validator - Gitter
I'm trying to use class validator for validatin my inputtype in type-graphql but the @matches decorator, is not working, All other decorators with...
Read more >
Validating nested objects with class-validator in NestJS
Today I have for you a quick and short article. Maybe it will help someone. I'm using class-validator for request validation in NestJS ......
Read more >
class-validator - npm.io
This will strip all properties that don't have any decorators. If no other decorator is suitable for your property, you can use @Allow...
Read more >
typestack/class-validator - CD2H gitForager
rt {ValidateNested} from "class-validator"; rt class Post ... If no other decorator is suitable for your property, you can use @Allow decorator:
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