- serves as both validator and documentation of your project's data models
- is sophisticated: environments, recursion detection, tolerant value adaptation, extendable
- makes your development more agile. You don't need to unit test your validators any more.
npm install schema
The environment is a context, where your schemas and validations live in. You need to create an environment before creating your schemas to define some default settings that will affect all schemas created in this environment:
var myEnv = 'envIdentifier' options
- The identifier is optional but recommended to retrieve the same environment - without options - in another script.
optionsis an object that can have the following keys:
'i18n'is a list of module identifiers or i18n packages that will be used inside this environment. To omit all messages in the validation errors, just use
. Example for an i18n module Default:
[ '../i18n/default' ]
'fallbacks'defines the default fallbacks that are used when a schema is defined without the
'STRICT_FALLBACKS'or any other legal definition of the
'v': Default and only supported option:
'detectRecursion'defines whether recursions should be detected on validation. Not recommended to set to
Instances contain a JSON Schema:
var schema = myEnvSchema
'pre'handler called before applying this schema. See example above.
'post'handler called after applying this schema.
Still not supported
'type': usage of schemas
- Hyper Schema
- URI references
Irrelevant for validation
When writing a new schema, you can use the file PROPERTY_OVERVIEW_02 to get a quick overview over all supported properties.
var validation = schemavar assert =assertassert