-
Notifications
You must be signed in to change notification settings - Fork 848
Open
Labels
type: questionQuestions about the usage of the library.Questions about the usage of the library.
Description
Problem:
I have implemented a validation decorator to ensure a property is defined when the given condition is met:
export function IsDefinedIf<A = any, B = any>(
condition: ConditionFunc<A, B>,
validationOptions?: ValidationOptions
) {
return function(type: Object, propertyName: string) {
registerDecorator({
name: 'isDefinedIf',
target: type.constructor,
propertyName: propertyName,
constraints: [condition],
options: validationOptions,
validator: {
validate(value: B, args: ValidationArguments) {
return !condition(args.object as A, value) || !isNullish(value);
},
defaultMessage(_args: ValidationArguments) {
return `${propertyName} should be defined`;
},
},
});
};
}
This decorator won't be executed when skipMissingProperties: true, which requires the same special treatment for @IsDefined.
Proposal:
Currently there is an always option in ValidationOptions:
export interface ValidationOptions {
/**
* Indicates if validation must be performed always, no matter of validation groups used.
*/
always?: boolean;
}
Can we extend it to also ignores skipMissingProperties option, or create a new option.
Many thanks for the great work!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type: questionQuestions about the usage of the library.Questions about the usage of the library.