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>[];
for (final MapEntry(:key, value: dependents) in dependencies.entries) {
// Only validate when the trigger property is present.
if (!value.containsKey(key)) continue;
for (final dependent in dependents) {
if (!value.containsKey(dependent)) {
// Emit one violation per missing dependent, with the path pointing
// at the missing property — consistent with RequiredRule path format.
violations.add(
SchemaViolation(
path: path.isEmpty ? dependent : '$path.$dependent',
message: 'required field is missing',
),
);
}
}
}
return violations;
}