annotate method

  1. @override
AnnotationResult annotate(
  1. dynamic cached,
  2. dynamic instance,
  3. DogEngine engine
)
override

Annotates instance with this validator returning an AnnotationResult. This mechanic is used to provide more information about the validation error.

Implementation

@override
AnnotationResult annotate(dynamic cached, dynamic instance, DogEngine engine) {
  final isValid = validate(cached, instance, engine);
  if (isValid) return AnnotationResult.empty();
  final entry = cached as MustMatchCacheEntry;
  return AnnotationResult(messages: [
    AnnotationMessage(
        id: messageId,
        message: "Must match field %otherField%",
        target: entry.fieldName,
        variables: {"field": entry.fieldName, "otherField": entry.otherFieldName})
  ]);
}