Class-validator: ValidateNested without decorator is not working

Created on 23 May 2018  路  7Comments  路  Source: typestack/class-validator

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?

blocked fix

Most helpful comment

@NoNameProvided any news on this?

All 7 comments

@NoNameProvided any news on this?

the decorator ValidateNested doesnt seems to work either

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

@rlataguerra Are you experiencing the same as I with ValidateNested decorator? Can you also check @NoNameProvided and @19majkel94 Check this: https://github.com/typestack/class-validator/issues/281

@NoNameProvided there is some estimation to fix this issue?

馃槥 so I guess this is still a problem with no fix on the roadmap...

I'm trying to dynamically generate a validation schema based on the results of an xhr request, and building a class isn't possible...

Marking this as blocked, as I want to start a discussion around the deprecation of the schema-based validation. I will CC the participants once I have created the issue.

Was this page helpful?
0 / 5 - 0 ratings