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 (value is! Map) return [];
  return [
    for (final field in fields)
      if (!value.containsKey(field))
        SchemaViolation(
          path: path.isEmpty ? field : '$path.$field',
          message: 'required field is missing',
        ),
  ];
}