performValidation method

  1. @override
void performValidation(
  1. String? path,
  2. dynamic value,
  3. List<ValidationResult> results
)
override

Validates a given value against the schema and configured validation rules.

  • path a dot notation path to the value.
  • value a value to be validated.
  • results a list with validation results to add new results.

Implementation

@override
void performValidation(
    String? path, dynamic value, List<ValidationResult> results) {
  value = ObjectReader.getValue(value);

  super.performValidation(path, value, results);

  if (value == null) return;

  var name = path ?? 'value';
  var valueType = TypeConverter.toTypeCode(value);
  var map = valueType == TypeCode.Map ? Map.from(value) : null;

  if (map != null) {
    for (var key in map.keys) {
      var elementPath = path != '' && path != null
          ? path + '.' + key
          : StringConverter.toString2(key);

      performTypeValidation(elementPath, getKeyType(), key, results);
      performTypeValidation(elementPath, getValueType(), map[key], results);
    }
  } else {
    if (isRequired()) {
      results.add(ValidationResult(
          path,
          ValidationResultType.Error,
          'VALUE_ISNOT_MAP',
          name + ' type must be Map',
          TypeCode.Map,
          valueType));
    }
  }
}