docs: modifying option in custom keyword definition, closes #392

master
Evgeny Poberezkin 2017-01-20 22:16:11 +00:00
parent 33845cc397
commit d314df2721
2 changed files with 4 additions and 3 deletions

View File

@ -25,7 +25,7 @@ Validation function will be called during data validation and it will be passed:
- the property name in the parent data object
- the root data
The access to the parent data object and the current property name allow to create keywords that modify the validated data.
The access to the parent data object and the current property name allow to create keywords that modify the validated data (`modifying` option MUST be used in keyword definition in this case).
The function should return validation result as boolean. It can return an array of validation errors via `.errors` property of itself (otherwise a standard error will be used).
@ -75,7 +75,7 @@ Compilation function will be called during schema compilation. It will be passed
- the property name in the parent data object
- the root data
The access to the parent data object and the current property name allow to create keywords that modify the validated data.
The access to the parent data object and the current property name allow to create keywords that modify the validated data (`modifying` option MUST be used).
The function should return validation result as boolean. It can return an array of validation errors via `.errors` property of itself (otherwise a standard error will be used).

View File

@ -350,7 +350,7 @@ The advantages of using custom keywords are:
- simplify your schemas
- help bringing a bigger part of the validation logic to your schemas
- make your schemas more expressive, less verbose and closer to your application domain
- implement custom data processors that modify your data and/or create side effects while the data is being validated
- implement custom data processors that modify your data (`modifying` option MUST be used in keyword definition) and/or create side effects while the data is being validated
The concerns you have to be aware of when extending JSON-schema standard with custom keywords are the portability and understanding of your schemas. You will have to support these custom keywords on other platforms and to properly document these keywords so that everybody can understand them in your schemas.
@ -925,6 +925,7 @@ Keyword definition is an object with the following properties:
- _inline_: compiling function that returns code (as string)
- _schema_: an optional `false` value used with "validate" keyword to not pass schema
- _metaSchema_: an optional meta-schema for keyword schema
- _modifying_: `true` MUST be passed if keyword modifies data.
- _$data_: an optional `true` value to support [$data reference](#data-reference) as the value of custom keyword. The reference will be resolved at validation time. If the keyword has meta-schema it would be extended to allow $data and it will be used to validate the resolved value. Supporting $data reference requires that keyword has validating function (as the only option or in addition to compile, macro or inline function).
- _async_: an optional `true` value if the validation function is asynchronous (whether it is compiled or passed in _validate_ property); in this case it should return a promise that resolves with a value `true` or `false`. This option is ignored in case of "macro" and "inline" keywords.
- _errors_: an optional boolean indicating whether keyword returns errors. If this property is not set Ajv will determine if the errors were set in case of failed validation.