Skip to content

Commit 7109c71

Browse files
vadyvasAlbina Blazhko
andauthored
chore: sync with origin (#29)
--------- Co-authored-by: Albina Blazhko <[email protected]>
1 parent 5c93dcc commit 7109c71

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+764
-197
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: build
1+
name: build & test
22

33
on:
44
push:
@@ -12,26 +12,15 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
node-version: [16.x]
15+
node-version: [16.x, 18.x, 20.x, 21.x]
1616

1717
steps:
18-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v4
1919
- name: use Node.js ${{ matrix.node-version }}
20-
uses: actions/setup-node@v2
20+
uses: actions/setup-node@v4
2121
with:
2222
node-version: ${{ matrix.node-version }}
2323
- run: npm install
2424
- run: git submodule update --init
25-
# - name: update website
26-
# if: ${{ github.event_name == 'push' && matrix.node-version == '14.x' }}
27-
# run: ./scripts/publish-site
28-
# env:
29-
# GH_TOKEN_PUBLIC: ${{ secrets.GH_TOKEN_PUBLIC }}
30-
# GIT_USER_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
31-
# GIT_USER_NAME: ${{ secrets.GIT_USER_NAME }}
3225
- run: npm run build
3326
- run: npm run test-ci
34-
# - name: coveralls
35-
# uses: coverallsapp/github-action@master
36-
# with:
37-
# github-token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/publish.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ on:
77
jobs:
88
publish-npm:
99
runs-on: ubuntu-latest
10+
permissions:
11+
id-token: write # Required for OIDC
12+
contents: read
1013
steps:
11-
- uses: actions/checkout@v2
12-
- uses: actions/setup-node@v2
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-node@v4
1316
with:
14-
node-version: 14
15-
registry-url: https://registry.npmjs.org/
17+
node-version: 18
1618
- run: npm install
1719
- run: git submodule update --init
1820
- run: npm run test-ci
1921
- name: Publish beta version to npm
20-
if: "github.event.release.prerelease"
22+
if: ${{ github.event.release.prerelease }}
2123
run: npm publish --tag beta
22-
env:
23-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2424
- name: Publish to npm
25-
if: "!github.event.release.prerelease"
25+
if: ${{ !github.event.release.prerelease }}
2626
run: npm publish
2727
env:
2828
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

README.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ The fastest JSON validator for Node.js and browser.
88

99
Supports JSON Schema draft-04/06/07/2019-09/2020-12 ([draft-04 support](https://ajv.js.org/json-schema.html#draft-04) requires ajv-draft-04 package) and JSON Type Definition [RFC8927](https://datatracker.ietf.org/doc/rfc8927/).
1010

11-
[![build](https://github.com/ajv-validator/ajv/workflows/build/badge.svg)](https://github.com/ajv-validator/ajv/actions?query=workflow%3Abuild)
11+
[![build](https://github.com/ajv-validator/ajv/actions/workflows/build.yml/badge.svg)](https://github.com/ajv-validator/ajv/actions?query=workflow%3Abuild)
1212
[![npm](https://img.shields.io/npm/v/ajv.svg)](https://www.npmjs.com/package/ajv)
1313
[![npm downloads](https://img.shields.io/npm/dm/ajv.svg)](https://www.npmjs.com/package/ajv)
1414
[![Coverage Status](https://coveralls.io/repos/github/ajv-validator/ajv/badge.svg?branch=master)](https://coveralls.io/github/ajv-validator/ajv?branch=master)
15-
[![SimpleX](https://img.shields.io/badge/chat-on%20SimpleX-%2307b4b9)](https://simplex.chat/contact#/?v=1&smp=smp%3A%2F%2Fu2dS9sG8nMNURyZwqASV4yROM28Er0luVTx5X1CsMrU%3D%40smp4.simplex.im%2Fap4lMFzfXF8Hzmh-Vz0WNxp_1jKiOa-h%23MCowBQYDK2VuAyEAcdefddRvDfI8iAuBpztm_J3qFucj8MDZoVs_2EcMTzU%3D)
15+
[![SimpleX](https://img.shields.io/badge/chat-on%20SimpleX-70F0F9)](https://simplex.chat/contact#/?v=1-2&smp=smp%3A%2F%2Fu2dS9sG8nMNURyZwqASV4yROM28Er0luVTx5X1CsMrU%3D%40smp4.simplex.im%2F8KvvURM6J38Gdq9dCuPswMOkMny0xCOJ%23%2F%3Fv%3D1-2%26dh%3DMCowBQYDK2VuAyEAr8rPVRuMOXv6kwF2yUAap-eoVg-9ssOFCi1fIrxTUw0%253D%26srv%3Do5vmywmrnaxalvz6wi3zicyftgio6psuvyniis6gco6bp6ekl4cqj4id.onion&data=%7B%22type%22%3A%22group%22%2C%22groupLinkId%22%3A%224pwLRgWHU9tlroMWHz0uOg%3D%3D%22%7D)
1616
[![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv)
1717
[![GitHub Sponsors](https://img.shields.io/badge/$-sponsors-brightgreen)](https://github.com/sponsors/epoberezkin)
1818

@@ -35,6 +35,7 @@ Please review [Contributing guidelines](./CONTRIBUTING.md) and [Code components]
3535
All documentation is available on the [Ajv website](https://ajv.js.org).
3636

3737
Some useful site links:
38+
3839
- [Getting started](https://ajv.js.org/guide/getting-started.html)
3940
- [JSON Schema vs JSON Type Definition](https://ajv.js.org/guide/schema-language.html)
4041
- [API reference](https://ajv.js.org/api.html)
@@ -53,7 +54,7 @@ Your continuing support is very important - the funds will be used to develop an
5354
Please sponsor Ajv via:
5455

5556
- [GitHub sponsors page](https://github.com/sponsors/epoberezkin) (GitHub will match it)
56-
- [Ajv Open Collective️](https://opencollective.com/ajv)
57+
- [Ajv Open Collective](https://opencollective.com/ajv)
5758

5859
Thank you.
5960

@@ -73,6 +74,19 @@ Thank you.
7374
<a href="https://opencollective.com/ajv/organization/9/website"><img src="https://opencollective.com/ajv/organization/9/avatar.svg"></a>
7475
<a href="https://opencollective.com/ajv/organization/10/website"><img src="https://opencollective.com/ajv/organization/10/avatar.svg"></a>
7576
<a href="https://opencollective.com/ajv/organization/11/website"><img src="https://opencollective.com/ajv/organization/11/avatar.svg"></a>
77+
<a href="https://opencollective.com/ajv/organization/12/website"><img src="https://opencollective.com/ajv/organization/12/avatar.svg"></a>
78+
<a href="https://opencollective.com/ajv/organization/13/website"><img src="https://opencollective.com/ajv/organization/13/avatar.svg"></a>
79+
<a href="https://opencollective.com/ajv/organization/14/website"><img src="https://opencollective.com/ajv/organization/14/avatar.svg"></a>
80+
<a href="https://opencollective.com/ajv/organization/15/website"><img src="https://opencollective.com/ajv/organization/15/avatar.svg"></a>
81+
<a href="https://opencollective.com/ajv/organization/16/website"><img src="https://opencollective.com/ajv/organization/16/avatar.svg"></a>
82+
<a href="https://opencollective.com/ajv/organization/17/website"><img src="https://opencollective.com/ajv/organization/17/avatar.svg"></a>
83+
<a href="https://opencollective.com/ajv/organization/18/website"><img src="https://opencollective.com/ajv/organization/18/avatar.svg"></a>
84+
<a href="https://opencollective.com/ajv/organization/19/website"><img src="https://opencollective.com/ajv/organization/19/avatar.svg"></a>
85+
<a href="https://opencollective.com/ajv/organization/20/website"><img src="https://opencollective.com/ajv/organization/20/avatar.svg"></a>
86+
<a href="https://opencollective.com/ajv/organization/21/website"><img src="https://opencollective.com/ajv/organization/21/avatar.svg"></a>
87+
<a href="https://opencollective.com/ajv/organization/22/website"><img src="https://opencollective.com/ajv/organization/22/avatar.svg"></a>
88+
<a href="https://opencollective.com/ajv/organization/23/website"><img src="https://opencollective.com/ajv/organization/23/avatar.svg"></a>
89+
<a href="https://opencollective.com/ajv/organization/24/website"><img src="https://opencollective.com/ajv/organization/24/avatar.svg"></a>
7690

7791
## Performance
7892

@@ -87,7 +101,7 @@ Currently Ajv is the fastest and the most standard compliant validator according
87101

88102
Performance of different validators by [json-schema-benchmark](https://github.com/ebdrup/json-schema-benchmark):
89103

90-
[![performance](https://chart.googleapis.com/chart?chxt=x,y&cht=bhs&chco=76A4FB&chls=2.0&chbh=62,4,1&chs=600x416&chxl=-1:|ajv|@exodus&#x2F;schemasafe|is-my-json-valid|djv|@cfworker&#x2F;json-schema|jsonschema&chd=t:100,69.2,51.5,13.1,5.1,1.2)](https://github.com/ebdrup/json-schema-benchmark/blob/master/README.md#performance)
104+
[![performance](https://chart.googleapis.com/chart?chxt=x,y&cht=bhs&chco=76A4FB&chls=2.0&chbh=62,4,1&chs=600x416&chxl=-1:|ajv|@exodus/schemasafe|is-my-json-valid|djv|@cfworker/json-schema|jsonschema/=t:100,69.2,51.5,13.1,5.1,1.2)](https://github.com/ebdrup/json-schema-benchmark/blob/master/README.md#performance)
91105

92106
## Features
93107

@@ -144,15 +158,15 @@ const schema = {
144158
type: "object",
145159
properties: {
146160
foo: {type: "integer"},
147-
bar: {type: "string"}
161+
bar: {type: "string"},
148162
},
149163
required: ["foo"],
150164
additionalProperties: false,
151165
}
152166

153167
const data = {
154168
foo: 1,
155-
bar: "abc"
169+
bar: "abc",
156170
}
157171

158172
const validate = ajv.compile(schema)

docs/api.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Every time this method is called the errors are overwritten so you need to copy
149149

150150
If the schema is asynchronous (has `$async` keyword on the top level) this method returns a Promise. See [Asynchronous validation](./guide/async-validation.md).
151151

152-
<a name="add-schema"></a>
152+
<a id="add-schema"></a>
153153

154154
### ajv.addSchema(schema: object | object[], key?: string): Ajv
155155

@@ -245,13 +245,13 @@ Formats can be also added via `formats` option.
245245

246246
<a name="api-addkeyword"></a>
247247

248-
### ajv.addKeyword(definition: object): Ajv
248+
### ajv.addKeyword(definition: string | object): Ajv
249249

250250
Add validation keyword to Ajv instance.
251251

252252
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.
253253

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 `:`.
255255
It is recommended to use an application-specific prefix for keywords to avoid current and future name collisions.
256256

257257
Example Keywords:
@@ -297,6 +297,8 @@ interface KeywordDefinition {
297297
}
298298
```
299299

300+
If only the property `keyword` is provided in the definition object, you can also pass the keyword name as the argument.
301+
300302
`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).
301303

302304
::: tip Keyword is validated only for applicable data types

docs/guide/combining-schemas.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const ajv = new Ajv()
4141
const validate = ajv.addSchema(defsSchema).compile(schema)
4242
```
4343

44-
See [Options](./api.md#options) and [addSchema](./api.md#add-schema) method.
44+
See [Options](../options.md) and [addSchema](../api.md#add-schema) method.
4545

4646
::: tip Reference resolution
4747
- `$ref` is resolved as the uri-reference using schema \$id as the base URI (see the example).

docs/guide/getting-started.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
You can try Ajv without installing it in the Node.js REPL: [https://runkit.com/npm/ajv](https://runkit.com/npm/ajv)
99
:::
1010

11-
To install Ajv version 7:
11+
To install Ajv version 8:
1212

1313
```bash
1414
npm install ajv
@@ -140,8 +140,8 @@ const parse = ajv.compileParser(schema)
140140
const json = '{"foo": 1, "bar": "abc"}'
141141
const invalidJson = '{"unknown": "abc"}'
142142

143-
console.log(parseAndLog(json)) // logs {foo: 1, bar: "abc"}
144-
console.log(parseAndLog(invalidJson)) // logs error and position
143+
parseAndLog(json) // logs {foo: 1, bar: "abc"}
144+
parseAndLog(invalidJson) // logs error and position
145145

146146
function parseAndLog(json) {
147147
const data = parse(json)

docs/guide/managing-schemas.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ app.post("/user", async (cxt) => {
8888
</code-group>
8989

9090
::: warning Use single Ajv instance
91-
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:
9292

9393
- require Ajv in a separate module responsible for validation
9494
- compile all validators there
@@ -186,7 +186,7 @@ In the example above, the key passed to the `addSchema` method was used to retri
186186

187187
### Pre-adding all schemas vs adding on demand
188188

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:
190190

191191
```javascript
192192
const schema_user = require("./schema_user.json")

docs/guide/modifying-data.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ See [discriminator](../json-schema.md#discriminator) keyword.
154154

155155
## Assigning defaults
156156

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.
158158

159159
With the option value `"empty"` properties and items equal to `null` or `""` (empty string) will be considered missing and assigned defaults.
160160

@@ -210,7 +210,7 @@ With `useDefaults` option `default` keywords throws exception during schema comp
210210

211211
The strict mode option can change the behaviour for these unsupported defaults (`strict: false` to ignore them, `"log"` to log a warning).
212212

213-
See [Strict mode](./strict-mode.md).
213+
See [Strict mode](../strict-mode.md).
214214

215215
::: tip Default with discriminator keyword
216216
Defaults will be assigned in schemas inside `oneOf` in case [discriminator](../json-schema.md#discriminator) keyword is used.

docs/guide/schema-language.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
tags:
33
- JTD
44
---
5+
56
# Choosing schema language
67

78
[[toc]]
@@ -70,7 +71,7 @@ Draft-2019-09 support is provided via a separate export in order to avoid increa
7071
With this import Ajv supports the following features:
7172

7273
- keywords [`unevaluatedProperties`](../json-schema.md#unevaluatedproperties) and [`unevaluatedItems`](../json-schema.md#unevaluateditems)
73-
- keywords [`dependentRequired`](../json-schema.md#dependentrequired), [`dependentSchemas`](../json-schema.md#dependentschemas), [`maxContains`/`minContain`](../json-schema.md#maxcontains--mincontains)
74+
- keywords [`dependentRequired`](../json-schema.md#dependentrequired), [`dependentSchemas`](../json-schema.md#dependentschemas), [`maxContains`/`minContains`](../json-schema.md#maxcontains-mincontains)
7475
- dynamic recursive references with [`recursiveAnchor`/`recursiveReference`] - see [Extending recursive schemas](./combining-schemas.md#extending-recursive-schemas)
7576
- draft-2019-09 meta-schema is the default.
7677

@@ -123,17 +124,19 @@ See [JSON Schema](../json-schema.md) for more information and the list of define
123124
- Defines the shape of JSON data via strictly defined schema forms (rather than the collection of restrictions).
124125
- Effective support for tagged unions.
125126
- 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.
128130

129131
**Cons**:
130132

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.
134137

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.
136139

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.
138141

139142
See [JSON Type Definition](../json-type-definition.md) for more information and the list of defined schema forms.

docs/json-schema.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ The value of the keyword should be a number. The data to be valid should be a mu
280280

281281
### `maxLength` / `minLength`
282282

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+
283287
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.
284288

285289
**Examples**
@@ -474,11 +478,11 @@ To create and equivalent schema in draft-2020-12 use keywords [prefixItems](#pre
474478

475479
The value of the keyword should be a boolean or an object.
476480

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 in this 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 in this case - see [Strict mode](./strict-mode.md)
478482

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.
480484

481-
If the length of data 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:
482486

483487
- `false`: data is invalid
484488
- `true`: data is valid

0 commit comments

Comments
 (0)