MapSchema class

Schema to validate maps.

Example

var schema =  MapSchema(TypeCode.String, TypeCode.Integer);

schema.validate({ 'key1': 'A', 'key2': 'B' });       // Result: no errors
schema.validate({ 'key1': 1, 'key2': 2 });           // Result: element type mismatch
schema.validate([ 1, 2, 3 ]);                        // Result: type mismatch
Inheritance
Implementers

Constructors

MapSchema([dynamic keyType, dynamic valueType, bool? req, List<IValidationRule>? rules])
Creates a new instance of validation schema and sets its values.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

getKeyType() → dynamic
Gets the type of map keys. Null means that keys may have any type.
getRules() List<IValidationRule>?
Gets validation rules to check values against.
inherited
getValueType() → dynamic
Gets the type of map values. Null means that values may have any type.
isRequired() bool
Gets a flag that always requires non-null values. For null values it raises a validation error.
inherited
makeOptional() Schema
Makes validated values optional. Validation for null values will be skipped.
inherited
makeRequired() Schema
Makes validated values always required (non-null). For null values the schema will raise errors.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
performTypeValidation(String? path, dynamic type, dynamic value, List<ValidationResult> results) → void
Validates a given value to match specified type. The type can be defined as a Schema, type, a type name or TypeCode When type is a Schema, it executes validation recursively against that Schema.
inherited
performValidation(String? path, dynamic value, List<ValidationResult> results) → void
Validates a given value against the schema and configured validation rules.
override
setKeyType(dynamic value) → void
Sets the type of map keys. Null means that keys may have any type.
setRequired(bool value) → void
Sets a flag that always requires non-null values.
inherited
setRules(List<IValidationRule> value) → void
Sets validation rules to check values against.
inherited
setValueType(dynamic value) → void
Sets the type of map values. Null means that values may have any type.
toString() String
A string representation of this object.
inherited
validate(dynamic value) List<ValidationResult>
Validates the given value and results validation results.
inherited
validateAndReturnException(String? correlationId, dynamic value, [bool strict = false]) ValidationException?
Validates the given value and returns a ValidationException if errors were found.
inherited
validateAndThrowException(String? correlationId, dynamic value, [bool strict = false]) → void
Validates the given value and throws a ValidationException if errors were found.
inherited
withRule(IValidationRule rule) Schema
Adds validation rule to this schema.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited