ObjectSchema class

Schema to validate user defined objects.

Example

var schema =  ObjectSchema(false)
    .withOptionalProperty('id', TypeCode.String)
    .withRequiredProperty('name', TypeCode.String);

schema.validate({ id: '1', name: 'ABC' });       // Result: no errors
schema.validate({ name: 'ABC' });                // Result: no errors
schema.validate({ id: 1, name: 'ABC' });         // Result: id type mismatch
schema.validate({ id: 1, _name: 'ABC' });        // Result: name is missing, unexpected _name
schema.validate('ABC');                          // Result: type mismatch
Inheritance
Implementers

Constructors

ObjectSchema([bool allowUndefined, bool req, List<IValidationRule> rules ])
Creates a new validation schema and sets its values. [...]

Properties

isUndefinedAllowed ↔ bool
Gets flag to allow undefined properties [...]
read / write
hashCode → int
The hash code for this object. [...]
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

allowUndefined(bool value) ObjectSchema
Sets flag to allow undefined properties [...]
getProperties() → List<PropertySchema>
Gets validation schemas for object properties. [...]
performValidation(String path, dynamic value, List<ValidationResult> results) → void
Validates a given value against the schema and configured validation rules. [...]
override
setProperties(List<PropertySchema> value) → void
Sets validation schemas for object properties. [...]
withOptionalProperty(String name, [ dynamic type, List<IValidationRule> rules ]) ObjectSchema
Adds a validation schema for an optional object property. [...]
withProperty(PropertySchema schema) → dynamic
Adds a validation schema for an object property. [...]
withRequiredProperty(String name, [ dynamic type, List<IValidationRule> rules ]) ObjectSchema
Adds a validation schema for a required object property. [...]
getRules() → List<IValidationRule>
Gets validation rules to check values against. [...]
inherited
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 non-existent 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
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
toString() → String
Returns 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 ==(dynamic other) → bool
The equality operator. [...]
inherited