topolis / validator
yaml based schema validation for multidimensional arrays
Installs: 652
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/topolis/validator
This package is not auto-updated.
Last update: 2025-10-14 18:10:18 UTC
README
A complex validator that applies a yaml based schema file to a multi dimensional array
Syntax
A schema is a hirarchical Yaml file. Each level, starting from the root of the file contains one of 3 different constructs.
Properties
Properties is an object with a list of named properties. Each property can then contain other constructs. The Yaml representation of an object construct is:
Options
typedefines if the property contains one sub construct or an array of sub constructs. Default:singleconditionalsa list of conditionals (need to contain a properties key if they are to replace the base object). Default:undefineddefaultThe default value if nothing is found. Default:undefined(will simply remove the property)requiredDefines if this property must be present. Default:falsefilterIf type ismultiple, this filter will be usedto validate the array keys. Default:undefinedoptionsIf type ismultiple, these are the options for the key filter. Default:[]propertiesThe array of properties of this object. Default:[]errorsindividual status codes can be overriden with custom codes and messages for this one validation rule. Default:[](See below=
Sample
properties:
one:
...
two:
...
three:
...
required: true
default: {one: A}
Listing
This defines a key value array. The difference to an object is that keys are not strictly defined but only need to pass a filter.
Options
conditionalsa list of conditionals (need to contain a properties key if they are to replace the base object). Default:undefineddefaultThe default value if nothing is found. Default:undefined(will simply remove the property)requiredDefines if this property must be present. Default:falseminThe required minimum number of array elements. Default:falsemaxThe required maximum number of array elements. Default:falsekeyNeeds to contain a Value construct with the filter to use for array keys. Default:undefinedvalueNeeds to contain a construct for array items. Default:undefined
Sample
listing:
required: true
min: 2
max: 10
key:
...
value:
...
Value
This defines a singular value.
Options
filterThe filter to use (@see Topolis/Filter). Default:PassthroughoptionsThe options for this filter. Default:[](Keep in mind that Validator sets the default type of filters tosingle)strictDefines if a value is allowed to be sanitized if possible or not. Default:falsedefaultThe default value if nothing is found. Default:undefined(will simply remove the property)requiredDefines if this property must be present. Default:false
Sample
filter: PlainExt
options: {characters: ".-_"}
required: true
default: Pustekuchen
Custom Errors
FOr each validation rule, a custom error can bespecified for individual status codes. Be carefull with custom codes though as there are certain rules expected from your validation results.
Positive/Negativefollowing typical process exit codes, any positive code is considered a success. Any negative code is considered a failureSeverityThe more negative a number is, the more dramatic is the error. Most calling programms expect correct values for invalid or sanitized results. Be carefull to not break your result code checks.
Default error codes
ERROR = -100A critical execution or configuration errorINVALID = -11The result did not pass the minimal required rulesSANITIZED = -2The result has non-critical problems. The values causeing these problems could be adjusted automaticallyINFO = -1The result is completely valid but there are informational messagesVALID = 1The result is completely valid
Sample
filter: PlainExt
options: {characters: ".-_"}
errors:
-2:
code: -1
message: This data could be sanitized but we think a info alone is enough
-11:
code: -192
message: This very special check failed
Open Tasks
- BUG: Definition wrong in StatusManager (Can't reproduce. Where?)
- FR: reference definitions in other files
- FR: Auto incremental indexes in listings