feat: reserve annotation keywords, closes #619

master
Evgeny Poberezkin 2017-11-12 08:57:13 +00:00
parent dd884fe93d
commit 9ce4d2351f
2 changed files with 20 additions and 3 deletions

View File

@ -38,6 +38,7 @@ ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json'));
- [Command line interface](#command-line-interface)
- Validation
- [Keywords](#validation-keywords)
- [Annotation keywords](#annotation-keywords)
- [Formats](#formats)
- [Combining schemas with $ref](#ref)
- [$data reference](#data-reference)
@ -212,6 +213,21 @@ With [ajv-keywords](https://github.com/epoberezkin/ajv-keywords) package Ajv als
See [JSON Schema validation keywords](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md) for more details.
## Annotation keywords
JSON Schema specification defines several annotation keywords that describe schema itself but do not perform any validation.
- `title` and `description`: information about the data represented by that schema
- `$comment` (NEW in draft-07): information for developers. With option `$comment` Ajv logs or passes the comment string to the user-supplied function. See [Options](#options).
- `default`: a default value of the data instance, see [Assigning defaults](#assigning-defaults).
- `examples` (NEW in draft-07): an array of data instances. Ajv does not check the validity of these instances against the schema.
- `readOnly` and `writeOnly` (NEW in draft-07): marks data-instance as read-only or write-only in relation to the source of the data (database, api, etc.).
- `contentEncoding`: [RFC 2045](https://tools.ietf.org/html/rfc2045#section-6.1 ), e.g., "base64".
- `contentMediaType`: [RFC 2046](https://tools.ietf.org/html/rfc2046), e.g., "image/png".
__Please note__: Ajv does not implement validation of the keywords `examples`, `contentEncoding` and `contentMediaType` but it reserves them. If you want to create a plugin that implements some of them, it should remove these kewords from the instance.
## Formats
The following formats are supported for string validation with "format" keyword:

View File

@ -20,9 +20,10 @@ module.exports = function rules() {
var ALL = [ 'type', '$comment' ];
var KEYWORDS = [
'$schema', '$id', 'id',
'title', 'description',
'default', 'definitions',
'$schema', '$id', 'id', '$data', 'title',
'description', 'default', 'definitions',
'examples', 'readOnly', 'writeOnly',
'contentMediaType', 'contentEncoding',
'additionalItems', 'then', 'else'
];
var TYPES = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ];