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 objects (maps); other types are silently skipped.
if (value is! Map) return [];
final violations = <SchemaViolation>[];
if (minProperties != null && value.length < minProperties!) {
violations.add(
SchemaViolation(
path: path,
message: 'must have at least $minProperties properties',
),
);
}
if (maxProperties != null && value.length > maxProperties!) {
violations.add(
SchemaViolation(
path: path,
message: 'must have at most $maxProperties properties',
),
);
}
return violations;
}