
Validators are used on classes and on class properties to ensure that a value that is being assigned to a property or a set of properties is a valid value. It applies only to CREATE and UPDATE operations.
Several validators are included with the Appirator modules that anyone can import into their own applications and modules. The validators can be assigned as needed to class properties. Many take parameters so they can be customised. Any validator in declared any module that is a dependency within another module or application can be used by that module or application.
Validators can be declared globally within a module or application or they can be defined directly inline with the property they are validating. The inline approach makes sense if the validator does not need to be shared globally and only applies to the specific property.
There are three validation phases, each intended to allow a deeper and more CPU or network intensive test on the value or values being assigned.
The validation phases are:
NotEmpty, Range or the regex Pattern
validators available in the Appirator core module.
Validation is broken up into 4 steps:
Property and property rules validation is only performed on properties that are being explicitly assigned through an HTTP request (PATCH or PUT) or where there has been an explicit change to the property via scripts. If a property is not being updated during an HTTP request or if the property is not modified in a script, then property validation for that property is not invoked. When properties have been modified through scripts, all modified properties, and the object itself, is validated as the object is saved.
All validation steps within a given validation phase are run through to their end irrespective of whether there are validation errors or along the way. Validation errors are collected and at the end of the phase and these are issued as a collection of validation errors to the caller. Note that the validation errors contain the name of the property, which allows client applications to highlight the failing field if desired.