-
Notifications
You must be signed in to change notification settings - Fork 836
Open
Labels
status: needs triageIssues which needs to be reproduced to be verified report.Issues which needs to be reproduced to be verified report.type: fixIssues describing a broken feature.Issues describing a broken feature.
Description
We are running our application in NestJS framework and we are getting an error when we do the validation on the array of objects. Especially when using ValidateNested annotation. on Array of objects that fail with "property should not exists"
From our package.json
"class-transformer": "0.5.1",
"class-validator": "^0.14.0",
Node : v18
export class PolDumpReq {
@Type(() => PolDump)
@IsArray({ always: true })
@ArrayMinSize(1, { always: true })
@IsNotEmpty({ each: true, always: true })
@ValidateNested({ always: true, each: true })
polDumps: PolDump[];
}
export class PolDump {
@IsInt({ always: true })
@IsNotEmpty({ always: true })
versionNum: number;
@IsString({ always: true })
@IsNotEmpty({ always: true })
polNumber: string;
@IsString({ always: true })
@IsNotEmpty({ always: true })
@Matches(Constants.DATE_FORMAT_REGEXP, { always: true, message: `effectiveDate. Use ISO format ${Constants.DATE_FORMAT}.` })
effectiveDate: string;
@IsString({ always: true })
@IsNotEmpty({ always: true })
@Matches(Constants.DATE_FORMAT_REGEXP, { always: true, message: `effectiveDate. Use ISO format ${Constants.DATE_FORMAT}.` })
expirationDate: string;
@Type(() => PolVehicleDump)
@IsArray({ always: true })
@ArrayMinSize(0, { always: true })
@IsOptional({ always: true })
@ValidateNested({ always: true })
polVehicleDumps: PolVehicleDump[];
}
export class PolVehicleDump {
@IsString()
@IsNotEmpty()
vin: string;
@IsInt()
@IsOptional()
year: number;
@IsString()
@IsOptional()
make: string;
@IsString()
@IsOptional()
model: string;
@IsInt()
@IsOptional()
vehicleTypeCode: number;
}
Request:
{
"polDumps": [
{
"polNumber": "123123",
"versionNum": 1,
"effectiveDate": "2020-12-10",
"expirationDate": "2021-12-10",
"polVehicleDumps": [
{
"vin": "XXXXXXX",
"year": 2005,
"make": "FREIGHTLINER",
"model": "CL120T",
"vehicleTypeCode": 7,
}
]
}
]
}
Response:
"polDumps.0.polVehicleDumps.0.property vin should not exist",
"polDumps.0.polVehicleDumps.0.property year should not exist",
"polDumps.0.polVehicleDumps.0.property make should not exist",
"polDumps.0.polVehicleDumps.0.property model should not exist",
"polDumps.0.polVehicleDumps.0.property vehicleTypeCode should not exist"
Expected behavior
Expected to pass the validation
Actual behavior
Nested objects fail the validation.
ikmnjrd, mokulus, rodrigocezarluz, oliverlockwood, 1241doobieC and 1 more
Metadata
Metadata
Assignees
Labels
status: needs triageIssues which needs to be reproduced to be verified report.Issues which needs to be reproduced to be verified report.type: fixIssues describing a broken feature.Issues describing a broken feature.