I have a nested form validation on my nestjs application, that returns the following result when a field has some error:
Current error message: "products.0.amount A quantidade do produto é obrigatória"
Expected error message: "A quantidade do produto é obrigatória"
For those examples above, I have a form with an attribute called product that is an array of objects
The issue is that I don't want to return the property name appended to the message, I want to return a clean message, readable for end users
export class CheckoutForm {
@ValidateNested({ always: true })
@Type(() => ProductForm)
products: ProductForm[];
}
export class ProductForm {
@IsString({ always: true, message: 'O nome do produto é obrigatório' })
name: string;
@Min(1, { always: true, message: 'O preço do produto é obrigatório' })
value: number;
@IsNotEmpty({
always: true,
message: 'A quantidade do produto é obrigatória',
})
amount: number;
}
Looks like this is an open issue with class-validator. https://github.com/typestack/class-validator/issues/614#issuecomment-807255434
Seems to be nested validation issues if more than one level, which would explain the issues that you are having.