V. Validation layer
The validation layer provides a set of predicates used in the property validation process. Predicates rely on descriptive definitions encoded at the ontology level, allowing an ad-hoc validation of data. To make things even easier to instantiate there are predefined predicates associated with all primitive concepts (Numeric, String, etc.).
{
"$type": "validation",
"$version": "1.0",
"$schema": "A01564DBBCB04816A9BFE5FB50723EFD3BBE119E",
"$id": "DA4B9237BACCCDF19C0760CAB7AEC4A8359010B0",
"$author": "Andrei",
"$description": "Provide properties value validation",
"validations": {
"name": {
"regex": "[a-zA-Z0-9]",
"max-length": "200"
},
"age": {
"required": true,
"range": "1:150"
},
"address": {
"required": true
},
"email": {
"regex": "/S+@S+.S+/"
},
"password": {
"required": true
},
"lastSeen": {
"date": "DD/MM/YYYY"
}
}
}
From a conceptual perspective, the validation rules are constructed based on a set of predefined predicates that are fixed rules defined at the ontology level. These predicates are specific to the definition domain and are mainly defined for primitive data types (e.g. regex, max-length, max, min, range, etc.).
The targeted concept and the container ontology is defined in the model header. The validations collection aggregates validators for all properties relating to the concept. Each property can have zero or multiple validation rules attached.
Validation rule schema contains two pieces of information: the predicate type and the predicate parameters. A predicate parameter represents the needed parameter for a specific predicate; it does not have a strict format because it depends on the used predicate.
Supported validations
Name | Description |
---|---|
required | Enforce a field as obligatory; otherwise, display an error message. |
minLength | Enforce a minimum character length constraint on a field; otherwise, display an error message. |
maxLength | Enforce a maximum character length constraint on a field; otherwise, display an error message. |
min | Enforce a minimum value constraint on a field; otherwise, display an error message. |
max | Enforce a maximum value constraint on a field; otherwise, display an error message. |
Validate the field to ensure it contains a properly formatted email address; otherwise, display an error message. | |
regex | Apply a regular expression pattern to the field for validation; otherwise, display an error message. |
date | Validate the field for proper date formatting; otherwise, display an error message. |
range | Ensure the field value falls within a specified range; otherwise, display an error message. |
content-type | Validating files based on their mime type. |