Class-validator: fix: regression in 0.8.5 to 0.9.1 property should not exists on result

Created on 9 Nov 2018  路  7Comments  路  Source: typestack/class-validator

Hello,

When upgrading my class-validator version from 0.8.5 to 0.9.1, I'm facing this error. But I don't see any link with the breaking change :/

It's the same bug corrected in v 0.8.5 but present in 0.8.4

Does anyone have an idea ?

needs discussion schema-based-validation low fix

Most helpful comment

I created a repository to reproduce this error :
https://github.com/BenjD90/class-validator-issue-283

{
    "target": {
        "body": "Message content"
    },
    "property": "body",
    "value": "Message content",
    "constraints": {
        "whitelistValidation": "property body should not exist"
    }
}

I need the fix @NoNameProvided and @zender did in v 0.9.1 about validating against a schema will validate against that one instead of every registered one :

All 7 comments

I created a repository to reproduce this error :
https://github.com/BenjD90/class-validator-issue-283

{
    "target": {
        "body": "Message content"
    },
    "property": "body",
    "value": "Message content",
    "constraints": {
        "whitelistValidation": "property body should not exist"
    }
}

I need the fix @NoNameProvided and @zender did in v 0.9.1 about validating against a schema will validate against that one instead of every registered one :

A fork that upgraded class-validator, and pass this test :
https://github.com/flyacts/routing-controllers

I still get this error with the following code:

export class DownloadFileRequest {
  @IsString()
  @Length(21) // nanoid length
  public _id!: string;

  @IsString()
  @MinLength(1)
  public userAgent!: string;

  @IsOptional()
  @ValidateNested()
  public transformation!: TransformationOptions;

  constructor(data: DownloadFileRequest) {
    Object.assign(this, {
      ...data,
      transformation: { fetchFormat: "auto", ...data.transformation },
    });
  }
}

export class TransformationOptions {
  @IsOptional()
  @IsPositive()
  public width?: number;

  @IsOptional()
  @IsPositive()
  public height?: number;

  @IsOptional()
  @IsIn([...CLOUDINARY_CROP_TYPES])
  public crop?: CloudinaryCropType;

  @IsOptional()
  @IsString()
  @MinLength(1)
  public fetchFormat?: string;

  constructor(data: TransformationOptions) {
    Object.assign(this, data);
  }
}

Validation fails for transformation property on DownloadFileRequest.

It's happening to me too when using

validateOrReject(this, {
            whitelist: true,
            forbidNonWhitelisted: true
        });

and nested DTOs.

Hi I am experiencing a similar issue with Typescript classes. Validation fails completely. Any updates on this?

Hi all!

Can you share your use-case of the library here? I am thinking about deprecating the schema-based validation as there are a lot of libraries to do that so we should focus on decorator based validation.

@NoNameProvided My use case of shcema-based validation is to validate dynamic data with validation defined in a metamodel.
For exemple, in my app, I can create a product with a description, the description max length is defined by the user on the attribute description. My product object is something like that :

const product: Product = {
  description-id: 'a description ... long or not'
};

the description-id is the id of the description attribute, so it is unknown at the transpilation (TS鈫扟S) time.

Why I use class-validator to validate this ?
To have a single validation error format, and to limit number of libraries dependence.

Is that more clear ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

otbe picture otbe  路  5Comments

TomMarius picture TomMarius  路  3Comments

twittwer picture twittwer  路  6Comments

jerradpatch picture jerradpatch  路  5Comments

ibox4real picture ibox4real  路  4Comments