validate method

  1. @override
List<SchemaViolation> validate(
  1. dynamic value,
  2. String path
)
override

Validates value at path and returns every violation found.

path is a dot-notation string identifying the location of value within the document (e.g. 'address.city', '' for the root). Violations use path as their SchemaViolation.path.

Implementation

@override
List<SchemaViolation> validate(dynamic value, String path) {
  if (_single != null) {
    // Single-type form: produce a targeted error message.
    if (!_matchesType(_single, value)) {
      return [SchemaViolation(path: path, message: 'expected type $_single')];
    }
    return [];
  }
  // Array form — value must match at least one listed type.
  for (final t in types) {
    if (_matchesType(t, value)) return [];
  }
  return [
    SchemaViolation(
      path: path,
      message: 'expected type to be one of: ${types.join(', ')}',
    ),
  ];
}