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! num) return [];
  final violations = <SchemaViolation>[];
  if (minimum != null && value < minimum!) {
    violations.add(
      SchemaViolation(path: path, message: 'must be >= $minimum'),
    );
  }
  if (maximum != null && value > maximum!) {
    violations.add(
      SchemaViolation(path: path, message: 'must be <= $maximum'),
    );
  }
  if (exclusiveMinimum != null && value <= exclusiveMinimum!) {
    violations.add(
      SchemaViolation(path: path, message: 'must be > $exclusiveMinimum'),
    );
  }
  if (exclusiveMaximum != null && value >= exclusiveMaximum!) {
    violations.add(
      SchemaViolation(path: path, message: 'must be < $exclusiveMaximum'),
    );
  }
  return violations;
}