resolveFieldMessageCodes method

  1. @override
List<String> resolveFieldMessageCodes(
  1. String errorCode,
  2. String objectName,
  3. String field,
  4. Type? fieldType,
)
override

The codes of an error of field of objectName with errorCode, most specific first. fieldType is the declared type of the field, null when unknown.

Implementation

@override
List<String> resolveFieldMessageCodes(
  String errorCode,
  String objectName,
  String field,
  Type? fieldType,
) {
  // Spring's algorithm: the field and its key-free forms qualified by
  // the object name, then unqualified plus the last path segment (and
  // its key-free forms), the field type and the bare code. A set drops
  // duplicates while keeping that order.
  final fields = _fieldList(field);
  final codes = <String>{
    for (final f in fields) _code(errorCode, '$objectName.$f'),
  };
  final dot = field.lastIndexOf('.');
  if (dot >= 0) {
    fields.addAll(_fieldList(field.substring(dot + 1)));
  }
  codes
    ..addAll([for (final f in fields) _code(errorCode, f)])
    ..addAll([
      if (fieldType != null) _code(errorCode, '$fieldType'),
      _code(errorCode, null),
    ]);
  return codes.toList();
}