I'm using NesteJs, i want @ValidateNested to skip properties that are not defined in the class and not to throw an error:
property should not exists
This is my classes:
export default class InitialConfigClass extends SharedInitialConfigClass {
@Transform((value) => plainToClass(SettingsClass, value))
@IsNotEmpty()
@ValidateNested()
@Type(() => SettingsClass)
settings!: SettingsClass;
}
export class SettingsClass {
@IsNotEmpty()
@ValidateNested()
@Type(() => FormatSettingsClass)
first_config!: FormatSettingsClass;
@IsNotEmpty()
@ValidateNested()
@Type(() => FormatSettingsClass)
second_config!: FormatSettingsClass;
[key: string]: any;
}
Purpose:
- I want to allow for sending other properties under settings object, without letting ValdiateNested throwing an error, and without defining them in SettingClass
You can apply turn on the skipMissingProperties option inside of the ValidateNested decorotator