validate method
- dynamic value,
- 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) {
// Applies only to numbers; other types are silently skipped.
if (value is! num) return [];
if (divisor == 0) {
return [
SchemaViolation(path: path, message: 'multipleOf divisor must be > 0'),
];
}
// Compute the quotient and check that its fractional part is negligibly
// small, guarding against IEEE-754 rounding in decimal arithmetic.
final quotient = value / divisor;
if ((quotient - quotient.roundToDouble()).abs() >= _epsilon) {
return [
SchemaViolation(path: path, message: 'must be a multiple of $divisor'),
];
}
return [];
}