You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -149,7 +149,7 @@ Every time this method is called the errors are overwritten so you need to copy
149
149
150
150
If the schema is asynchronous (has `$async` keyword on the top level) this method returns a Promise. See [Asynchronous validation](./guide/async-validation.md).
Keyword should be different from all standard JSON Schema keywords and different from previously defined keywords. There is no way to redefine keywords or to remove keyword definition from the instance.
253
253
254
-
Keyword must start with a letter, `_` or `$`, and may continue with letters, numbers, `_`, `$`, or `-`.
254
+
Keyword must start with an ASCII letter, `_` or `$`, and may continue with ASCII letters, numbers, `_`, `$`, `-`, or `:`.
255
255
It is recommended to use an application-specific prefix for keywords to avoid current and future name collisions.
256
256
257
257
Example Keywords:
@@ -297,6 +297,8 @@ interface KeywordDefinition {
297
297
}
298
298
```
299
299
300
+
If only the property `keyword` is provided in the definition object, you can also pass the keyword name as the argument.
301
+
300
302
`compile`, `macro` and `code` are mutually exclusive, only one should be used at a time. `validate` can be used separately or in addition to `compile` or `macro` to support [\$data reference](./guide/combining-schemas.md#data-reference).
301
303
302
304
::: tip Keyword is validated only for applicable data types
It recommended to use a single Ajv instance for the whole application, so if you use validation in more than one module, you should:
91
+
It is recommended to use a single Ajv instance for the whole application, so if you use validation in more than one module, you should:
92
92
93
93
- require Ajv in a separate module responsible for validation
94
94
- compile all validators there
@@ -186,7 +186,7 @@ In the example above, the key passed to the `addSchema` method was used to retri
186
186
187
187
### Pre-adding all schemas vs adding on demand
188
188
189
-
In the example above all schemas were added in advance. It is also possible, to add schemas as they are used - it can be helpful if there is many schemas. In this case, you need to check first whether the schema is already added by calling `getSchema` method - it would return `undefined` if not:
189
+
In the example above all schemas were added in advance. It is also possible, to add schemas as they are used - it can be helpful if there are many schemas. In this case, you need to check first whether the schema is already added by calling `getSchema` method - it would return `undefined` if not:
Copy file name to clipboardExpand all lines: docs/guide/modifying-data.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -154,7 +154,7 @@ See [discriminator](../json-schema.md#discriminator) keyword.
154
154
155
155
## Assigning defaults
156
156
157
-
With [option `useDefaults`](./api.md#options) Ajv will assign values from `default` keyword in the schemas of `properties` and `items` (when it is the array of schemas) to the missing properties and items.
157
+
With [option `useDefaults`](./options.md#options) Ajv will assign values from `default` keyword in the schemas of `properties` and `items` (when it is the array of schemas) to the missing properties and items.
158
158
159
159
With the option value `"empty"` properties and items equal to `null` or `""` (empty string) will be considered missing and assigned defaults.
160
160
@@ -210,7 +210,7 @@ With `useDefaults` option `default` keywords throws exception during schema comp
210
210
211
211
The strict mode option can change the behaviour for these unsupported defaults (`strict: false` to ignore them, `"log"` to log a warning).
212
212
213
-
See [Strict mode](./strict-mode.md).
213
+
See [Strict mode](../strict-mode.md).
214
214
215
215
::: tip Default with discriminator keyword
216
216
Defaults will be assigned in schemas inside `oneOf` in case [discriminator](../json-schema.md#discriminator) keyword is used.
- dynamic recursive references with [`recursiveAnchor`/`recursiveReference`] - see [Extending recursive schemas](./combining-schemas.md#extending-recursive-schemas)
75
76
- draft-2019-09 meta-schema is the default.
76
77
@@ -123,17 +124,19 @@ See [JSON Schema](../json-schema.md) for more information and the list of define
123
124
- Defines the shape of JSON data via strictly defined schema forms (rather than the collection of restrictions).
124
125
- Effective support for tagged unions.
125
126
- Designed to protect against user mistakes.
126
-
- Supports compilation of schemas to efficient [serializers and parsers](./getting-started.md#parsing-and-serializing-json) (no need to validate as a separate step)
127
-
- Approved as [RFC8927](https://datatracker.ietf.org/doc/rfc8927/)
127
+
- Supports compilation of schemas to efficient [serializers and parsers](./getting-started.md#parsing-and-serializing-json) (no need to validate as a separate step).
128
+
- Approved as [RFC8927](https://datatracker.ietf.org/doc/rfc8927/).
129
+
- Substantial industry adoption since it was standardized in 2020, Ajv v8.12.0 fixed all reported JTD bugs.
128
130
129
131
**Cons**:
130
132
131
-
- Limited, compared with JSON Schema - no support for untagged unions<sup>\*</sup>, conditionals, references between different schema files<sup>\*\*</sup>, etc.
132
-
- No meta-schema in the specification<sup>\*</sup>.
133
-
- Brand new - limited industry adoption (as of January 2021).
133
+
- Limited, compared with JSON Schema - no support for untagged unions<sup>1</sup>, conditionals, references between different schema files<sup>2</sup>, etc.
134
+
- No meta-schema in the specification<sup>3</sup>.
135
+
136
+
<sup>1</sup> Ajv defines non-standard keyword "union" that can be used inside "metadata" object.
134
137
135
-
<sup>\*</sup> Ajv defines meta-schema for JTD schemas and non-standard keyword "union" that can be used inside "metadata" object.
138
+
<sup>2</sup> You can still combine schemas from multiple files in the application code.
136
139
137
-
<sup>\*\*</sup> You can still combine schemas from multiple files in the application code.
140
+
<sup>3</sup> Ajv defines meta-schema for JTD schemas.
138
141
139
142
See [JSON Type Definition](../json-type-definition.md) for more information and the list of defined schema forms.
Copy file name to clipboardExpand all lines: docs/json-schema.md
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -280,6 +280,10 @@ The value of the keyword should be a number. The data to be valid should be a mu
280
280
281
281
### `maxLength` / `minLength`
282
282
283
+
::: warning Grapheme clusters will count as multiple characters
284
+
Certain charsets have characters that are made up of multiple Unicode code points. These [grapheme clusters](https://www.unicode.org/reports/tr29/tr29-17.html#Grapheme_Cluster_Boundaries) are counted as multiple in length calculations.
285
+
:::
286
+
283
287
The value of the keywords should be a number. The data to be valid should have length satisfying this rule. Unicode pairs are counted as a single character.
284
288
285
289
**Examples**
@@ -474,11 +478,11 @@ To create and equivalent schema in draft-2020-12 use keywords [prefixItems](#pre
474
478
475
479
The value of the keyword should be a boolean or an object.
476
480
477
-
If `items` keyword is not present or it is an object, `additionalItems` keyword should be ignored regardless of its value. By default Ajv will throw exception inthis case - see [Strict mode](./strict-mode.md)
481
+
`additionalItems` keyword is ignored if`items` keyword is not present or is an object. By default Ajv will throw exception inthis case - see [Strict mode](./strict-mode.md)
478
482
479
-
If `items` keyword is an array and data array has not more items than the length of`items` keyword value, `additionalItems` keyword is also ignored.
483
+
`additionalItems` keyword is ignored if`items` keyword has more elements than data array.
480
484
481
-
If the length ofdata array is bigger than the length of"items" keyword value than the result of the validation depends on the value of`additionalItems` keyword:
485
+
If the data array has more elements than the `items` keyword value then the result of the validation depends on the value of`additionalItems` keyword:
0 commit comments