From 7b574e764b4b9065308c6b98d948a7e3e16fa19a Mon Sep 17 00:00:00 2001 From: Dominik Broj <19861998+thetric@users.noreply.github.com> Date: Tue, 24 Sep 2019 10:12:16 +0200 Subject: [PATCH 01/32] docs(readme): add usage notes for TypeScript users --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index d645c3f70..845481207 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,11 @@ Try it in the Node.js REPL: https://tonicdev.com/npm/ajv The fastest validation call: ```javascript +// Node.js require: var Ajv = require('ajv'); +// or ESM/TypeScript import +import Ajv from 'ajv'; + var ajv = new Ajv(); // options can be passed, e.g. {allErrors: true} var validate = ajv.compile(schema); var valid = validate(data); @@ -165,6 +169,10 @@ The best performance is achieved when using compiled functions returned by `comp __Please note__: every time a validation function or `ajv.validate` are called `errors` property is overwritten. You need to copy `errors` array reference to another variable if you want to use it later (e.g., in the callback). See [Validation errors](#validation-errors) +__Note for TypeScript users__: `ajv` provides its own TypeScript declarations +out of the box, so you don't need to install the deprecated `@types/ajv` +module. + ## Using in browser From 4e240b78f2387577f860e6af3c2c9f0ae6e8ba31 Mon Sep 17 00:00:00 2001 From: cjancsar <51799534+cjancsar@users.noreply.github.com> Date: Tue, 29 Oct 2019 13:50:09 -0400 Subject: [PATCH 02/32] Update FAQ.md (#1115) - Fix type "sence" to "sense" --- FAQ.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FAQ.md b/FAQ.md index 472a5edb0..36ac967cd 100644 --- a/FAQ.md +++ b/FAQ.md @@ -83,7 +83,7 @@ There are several ways to implement the described logic that would allow two pro ##### Why the validation fails when I use option `removeAdditional` with the keyword `anyOf`/etc.? -This problem is related to the problem explained above - properties treated as additional in the sence of `additionalProperties` keyword, based on `properties`/`patternProperties` keyword in the same schema object. +This problem is related to the problem explained above - properties treated as additional in the sense of `additionalProperties` keyword, based on `properties`/`patternProperties` keyword in the same schema object. See the exemple in [Filtering Data](https://github.com/epoberezkin/ajv#filtering-data) section of readme. From 25266ef7c277754225333de33f2ee56556f3c377 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sun, 24 Nov 2019 10:57:22 +0000 Subject: [PATCH 03/32] docs: typescript issue template --- .github/ISSUE_TEMPLATE/typescript.md | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/typescript.md diff --git a/.github/ISSUE_TEMPLATE/typescript.md b/.github/ISSUE_TEMPLATE/typescript.md new file mode 100644 index 000000000..7385349b0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/typescript.md @@ -0,0 +1,42 @@ +--- +name: Missing or incorrect type definition +about: Please use for issues related to typescript types +title: '' +labels: 'typescript' +assignees: '' + +--- + + + +**What version of Ajv are you using? Does the issue happen if you use the latest version?** + + +**Your typescript code** + + + +```typescript + + +``` + + +**Typescript compiler error messages** + +``` + + +``` + +**Describe the change that should be made to address the issue?** + + +**Are you going to resolve the issue?** From 4e56bf6268aea25c6632ba52ea602d3ff7ee641d Mon Sep 17 00:00:00 2001 From: Leonardo Villela Date: Sun, 24 Nov 2019 11:01:27 +0000 Subject: [PATCH 04/32] Add dataPathArr to CompilationContext interface type definition (#1114) --- lib/ajv.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ajv.d.ts b/lib/ajv.d.ts index 5e7cfa7da..ba75f8d2d 100644 --- a/lib/ajv.d.ts +++ b/lib/ajv.d.ts @@ -243,6 +243,7 @@ declare namespace ajv { interface CompilationContext { level: number; dataLevel: number; + dataPathArr: string[]; schema: any; schemaPath: string; baseId: string; From 0e542bdcd6cc12c98513cf475928520fae32a00d Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" <23040076+greenkeeper[bot]@users.noreply.github.com> Date: Sun, 24 Nov 2019 11:09:54 +0000 Subject: [PATCH 05/32] chore(package): update del-cli to version 3.0.0 (#1084) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5c3dfc746..b517e6e8a 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "browserify": "^16.2.0", "chai": "^4.0.1", "coveralls": "^3.0.1", - "del-cli": "^2.0.0", + "del-cli": "^3.0.0", "dot": "^1.0.3", "eslint": "^6.0.0", "gh-pages-generator": "^0.2.3", From 8c4671473cf1b92c609bb01aad981d632b6d7066 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sun, 24 Nov 2019 11:40:48 +0000 Subject: [PATCH 06/32] chore(package): update uglify-js to version 3.6.9 (#1125) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b517e6e8a..54eec94c0 100644 --- a/package.json +++ b/package.json @@ -92,7 +92,7 @@ "pre-commit": "^1.1.1", "require-globify": "^1.3.0", "typescript": "^2.8.3", - "uglify-js": "^3.3.24", + "uglify-js": "^3.6.9", "watch": "^1.0.0" } } From d705f8e1e55d719cdc6c70ef89fd574616ce0b84 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sat, 14 Dec 2019 16:21:22 +0000 Subject: [PATCH 07/32] fix(package): update fast-deep-equal to version 3.1.1 (#1135) Closes #1129 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 54eec94c0..6f15e2dd0 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "homepage": "https://github.com/epoberezkin/ajv", "tonicExampleFilename": ".tonic_example.js", "dependencies": { - "fast-deep-equal": "^2.0.1", + "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", "json-schema-traverse": "^0.4.1", "uri-js": "^4.2.2" From f7beda09e7bf76b3d3e8f631cba8a9577fdc344a Mon Sep 17 00:00:00 2001 From: sambauers Date: Wed, 8 Jan 2020 10:59:21 +1100 Subject: [PATCH 08/32] Improved hostname validation. Allow trailing dot. Check for octet count rather than string length. --- lib/compile/formats.js | 13 ++++++++++-- spec/tests/rules/format.json | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/lib/compile/formats.js b/lib/compile/formats.js index d06792aa4..a5001c7b6 100644 --- a/lib/compile/formats.js +++ b/lib/compile/formats.js @@ -5,7 +5,7 @@ var util = require('./util'); var DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/; var DAYS = [0,31,28,31,30,31,30,31,31,30,31,30,31]; var TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i; -var HOSTNAME = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*$/i; +var HOSTNAME = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i; var URI = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i; var URIREF = /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i; // uri-template: https://tools.ietf.org/html/rfc6570 @@ -126,7 +126,16 @@ function date_time(str) { function hostname(str) { // https://tools.ietf.org/html/rfc1034#section-3.5 // https://tools.ietf.org/html/rfc1123#section-2 - return str.length <= 255 && HOSTNAME.test(str); + + // Count octets, not string length + // https://devblogs.microsoft.com/oldnewthing/?p=7873 + var count = str.length; + // Do not count trailing dot if present + if (/\.$/.test(str)) count--; + // Add leading and trailing "length octets" to count + count += 2; + + return count <= 255 && HOSTNAME.test(str); } diff --git a/spec/tests/rules/format.json b/spec/tests/rules/format.json index 226608bd4..e4b492dc6 100644 --- a/spec/tests/rules/format.json +++ b/spec/tests/rules/format.json @@ -82,10 +82,50 @@ "data": "123.example.com", "valid": true }, + { + "description": "valid hostname - trailing dot", + "data": "123.example.com.", + "valid": true + }, + { + "description": "valid hostname - single label", + "data": "localhost", + "valid": true + }, + { + "description": "valid hostname - single label with trailing dot", + "data": "localhost.", + "valid": true + }, { "description": "valid hostname #312", "data": "lead-routing-qa.lvuucj.0001.use1.cache.amazonaws.com", "valid": true + }, + { + "description": "valid hostname - maximum length label (63 chars)", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.example.com", + "valid": true + }, + { + "description": "invalid hostname - label too long (64 chars)", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl.example.com", + "valid": false + }, + { + "description": "valid hostname - maximum length hostname (255 octets)", + "data": "abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxy.example.com", + "valid": true + }, + { + "description": "valid hostname - maximum length hostname (255 octets) with trailing dot", + "data": "abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxy.example.com.", + "valid": true + }, + { + "description": "invalid hostname - hostname too long (256 octets)", + "data": "abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.example.com.", + "valid": false } ] }, From c3bbc3e35b09ba9ef5a2b6a4501c7b9812636d49 Mon Sep 17 00:00:00 2001 From: sambauers Date: Thu, 9 Jan 2020 11:52:52 +1100 Subject: [PATCH 09/32] More efficient hostname function. --- lib/compile/formats.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/compile/formats.js b/lib/compile/formats.js index a5001c7b6..429a1f29e 100644 --- a/lib/compile/formats.js +++ b/lib/compile/formats.js @@ -126,16 +126,15 @@ function date_time(str) { function hostname(str) { // https://tools.ietf.org/html/rfc1034#section-3.5 // https://tools.ietf.org/html/rfc1123#section-2 + if (!HOSTNAME.test(str)) return false; // Count octets, not string length // https://devblogs.microsoft.com/oldnewthing/?p=7873 - var count = str.length; + var octets = str.length; // Do not count trailing dot if present - if (/\.$/.test(str)) count--; - // Add leading and trailing "length octets" to count - count += 2; - - return count <= 255 && HOSTNAME.test(str); + if (/\.$/.test(str)) octets--; + // With starting and ending length octets this would be 255, not 253 + return octets <= 253; } From 508f640e640b1a404af3e1fe3c98776c0e05b302 Mon Sep 17 00:00:00 2001 From: sambauers Date: Thu, 9 Jan 2020 12:11:23 +1100 Subject: [PATCH 10/32] More terse hostname function. --- lib/compile/formats.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/compile/formats.js b/lib/compile/formats.js index 429a1f29e..f51a3b76f 100644 --- a/lib/compile/formats.js +++ b/lib/compile/formats.js @@ -126,15 +126,11 @@ function date_time(str) { function hostname(str) { // https://tools.ietf.org/html/rfc1034#section-3.5 // https://tools.ietf.org/html/rfc1123#section-2 - if (!HOSTNAME.test(str)) return false; - // Count octets, not string length // https://devblogs.microsoft.com/oldnewthing/?p=7873 - var octets = str.length; - // Do not count trailing dot if present - if (/\.$/.test(str)) octets--; + // Count octets, not string length (remove any trailing dot) // With starting and ending length octets this would be 255, not 253 - return octets <= 253; + return str.replace(/\.$/, '').length <= 253 && HOSTNAME.test(str); } From cc97b003f59db096171263a9ca6cf58936b3bc07 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" <23040076+greenkeeper[bot]@users.noreply.github.com> Date: Sat, 18 Jan 2020 08:07:05 +0000 Subject: [PATCH 11/32] chore(package): update nyc to version 15.0.0 (#1139) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6f15e2dd0..109e47663 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "karma-mocha": "^1.1.1", "karma-sauce-launcher": "^2.0.0", "mocha": "^6.0.0", - "nyc": "^14.0.0", + "nyc": "^15.0.0", "pre-commit": "^1.1.1", "require-globify": "^1.3.0", "typescript": "^2.8.3", From f38f2e4136c790b409b12528dd6acd51283654ab Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 18 Jan 2020 08:53:51 +0000 Subject: [PATCH 12/32] test: remove failing typescript test --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 109e47663..43479a6e8 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "build": "del-cli lib/dotjs/*.js \"!lib/dotjs/index.js\" && node scripts/compile-dots.js", "test-karma": "karma start", "test-browser": "del-cli .browser && npm run bundle && scripts/prepare-tests && npm run test-karma", - "test-all": "npm run test-ts && npm run test-cov && if-node-version 10 npm run test-browser", + "test-all": "npm run test-cov && if-node-version 10 npm run test-browser", "test": "npm run lint && npm run build && npm run test-all", "prepublish": "npm run build && npm run bundle", "watch": "watch \"npm run build\" ./lib/dot" From 03198c2b6d52ec5eb7ffbf7623f05db5372689a1 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 18 Jan 2020 09:00:24 +0000 Subject: [PATCH 13/32] 6.11.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 43479a6e8..da9218a83 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv", - "version": "6.10.2", + "version": "6.11.0", "description": "Another JSON Schema Validator", "main": "lib/ajv.js", "typings": "lib/ajv.d.ts", From d9661b442e02077bc355af554a9e7c61e6390763 Mon Sep 17 00:00:00 2001 From: sambauers Date: Wed, 22 Jan 2020 12:46:58 +1100 Subject: [PATCH 14/32] Do hostname character count in regexp. --- lib/compile/formats.js | 8 +++----- spec/tests/rules/format.json | 5 +++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/compile/formats.js b/lib/compile/formats.js index f51a3b76f..0e6e910fa 100644 --- a/lib/compile/formats.js +++ b/lib/compile/formats.js @@ -5,7 +5,7 @@ var util = require('./util'); var DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/; var DAYS = [0,31,28,31,30,31,30,31,31,30,31,30,31]; var TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i; -var HOSTNAME = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i; +var HOSTNAME = /^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i; var URI = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i; var URIREF = /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i; // uri-template: https://tools.ietf.org/html/rfc6570 @@ -126,11 +126,9 @@ function date_time(str) { function hostname(str) { // https://tools.ietf.org/html/rfc1034#section-3.5 // https://tools.ietf.org/html/rfc1123#section-2 - // https://devblogs.microsoft.com/oldnewthing/?p=7873 - // Count octets, not string length (remove any trailing dot) - // With starting and ending length octets this would be 255, not 253 - return str.replace(/\.$/, '').length <= 253 && HOSTNAME.test(str); + // https://tools.ietf.org/html/rfc1034#section-3.1 + return HOSTNAME.test(str); } diff --git a/spec/tests/rules/format.json b/spec/tests/rules/format.json index e4b492dc6..c316a6ee5 100644 --- a/spec/tests/rules/format.json +++ b/spec/tests/rules/format.json @@ -124,6 +124,11 @@ }, { "description": "invalid hostname - hostname too long (256 octets)", + "data": "abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.example.com", + "valid": false + }, + { + "description": "invalid hostname - hostname too long (256 octets) with trailing dot", "data": "abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.example.com.", "valid": false } From d3488073b16c54704bc10f7d89645b34c49b0204 Mon Sep 17 00:00:00 2001 From: RadiationSickness Date: Tue, 4 Feb 2020 10:09:47 -0500 Subject: [PATCH 15/32] Add custom logger example The current value description for the custom logger option is not easily understandable. Adding an example to this would be greatly beneficial. --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index d645c3f70..641a6a4de 100644 --- a/README.md +++ b/README.md @@ -1151,6 +1151,15 @@ Defaults: - _schemas_: an array or object of schemas that will be added to the instance. In case you pass the array the schemas must have IDs in them. When the object is passed the method `addSchema(value, key)` will be called for each schema in this object. - _logger_: sets the logging method. Default is the global `console` object that should have methods `log`, `warn` and `error`. Option values: - custom logger - it should have methods `log`, `warn` and `error`. If any of these methods is missing an exception will be thrown. + ```javascript + var ajv = new AJV.default({ + logger: { + log: log => console.log(log), + warn: () => null, + error: error => console.error(error), + }, + }); + ``` - `false` - logging is disabled. From 23ebb55c1ae8ef69bc464fd6a8e142e9b6ad813c Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Tue, 11 Feb 2020 09:58:45 +0200 Subject: [PATCH 16/32] fix(types) added undefined to getSchema() --- lib/ajv.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ajv.d.ts b/lib/ajv.d.ts index ba75f8d2d..c946096ad 100644 --- a/lib/ajv.d.ts +++ b/lib/ajv.d.ts @@ -80,9 +80,9 @@ declare namespace ajv { /** * Get compiled schema from the instance by `key` or `ref`. * @param {string} keyRef `key` that was passed to `addSchema` or full schema reference (`schema.id` or resolved id). - * @return {Function} schema validating function (with property `schema`). + * @return {Function} schema validating function (with property `schema`). Returns undefined if keyRef can't be resolved to an existing schema. */ - getSchema(keyRef: string): ValidateFunction; + getSchema(keyRef: string): ValidateFunction | undefined; /** * Remove cached schema(s). * If no parameter is passed all schemas but meta-schemas are removed. From 10f6cba4c561fdea1b762156b4823d0826db818e Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" <23040076+greenkeeper[bot]@users.noreply.github.com> Date: Tue, 11 Feb 2020 08:27:54 +0000 Subject: [PATCH 17/32] chore(package): update mocha to version 7.0.1 (#1156) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index da9218a83..5cfec97d2 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "karma-chrome-launcher": "^3.0.0", "karma-mocha": "^1.1.1", "karma-sauce-launcher": "^2.0.0", - "mocha": "^6.0.0", + "mocha": "^7.0.1", "nyc": "^15.0.0", "pre-commit": "^1.1.1", "require-globify": "^1.3.0", From 5a92f70f5f967d80e4599775dfc2c0b8647c1b23 Mon Sep 17 00:00:00 2001 From: RadiationSickness Date: Tue, 11 Feb 2020 10:58:20 -0500 Subject: [PATCH 18/32] Adjusting Example - Converting example to ES5 - Updating example to conform to other examples - Updating example to have custom warning message --- README.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 641a6a4de..cfa23b667 100644 --- a/README.md +++ b/README.md @@ -1152,12 +1152,18 @@ Defaults: - _logger_: sets the logging method. Default is the global `console` object that should have methods `log`, `warn` and `error`. Option values: - custom logger - it should have methods `log`, `warn` and `error`. If any of these methods is missing an exception will be thrown. ```javascript - var ajv = new AJV.default({ + var ajv = new Ajv({ logger: { - log: log => console.log(log), - warn: () => null, - error: error => console.error(error), - }, + log: function log(_log) { + return console.log(_log); + }, + warn: function warn(_warn) { + return console.warn("Custom Warning: ".concat(_warn)); + }, + error: function error(_error) { + return console.error(_error); + } + } }); ``` - `false` - logging is disabled. From d601e4856421f87c08c68abf45bc1d8397c5c47b Mon Sep 17 00:00:00 2001 From: Matti Manninen Date: Wed, 12 Feb 2020 16:27:07 +0200 Subject: [PATCH 19/32] Fixed the TypeScript type definition for Options' "format" --- lib/ajv.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ajv.d.ts b/lib/ajv.d.ts index c946096ad..29cdee59a 100644 --- a/lib/ajv.d.ts +++ b/lib/ajv.d.ts @@ -169,7 +169,7 @@ declare namespace ajv { jsonPointers?: boolean; uniqueItems?: boolean; unicode?: boolean; - format?: string; + format?: false | string; formats?: object; unknownFormats?: true | string[] | 'ignore'; schemas?: Array | object; From d127103db174ebb09a8a59143d335e54d343afb2 Mon Sep 17 00:00:00 2001 From: RadiationSickness Date: Wed, 12 Feb 2020 10:29:29 -0500 Subject: [PATCH 20/32] Move Logging Sample To Error Section Updated and moved logging sample to new Error Logging subsection --- README.md | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index cfa23b667..41d703dc8 100644 --- a/README.md +++ b/README.md @@ -1151,21 +1151,6 @@ Defaults: - _schemas_: an array or object of schemas that will be added to the instance. In case you pass the array the schemas must have IDs in them. When the object is passed the method `addSchema(value, key)` will be called for each schema in this object. - _logger_: sets the logging method. Default is the global `console` object that should have methods `log`, `warn` and `error`. Option values: - custom logger - it should have methods `log`, `warn` and `error`. If any of these methods is missing an exception will be thrown. - ```javascript - var ajv = new Ajv({ - logger: { - log: function log(_log) { - return console.log(_log); - }, - warn: function warn(_warn) { - return console.warn("Custom Warning: ".concat(_warn)); - }, - error: function error(_error) { - return console.error(_error); - } - } - }); - ``` - `false` - logging is disabled. @@ -1302,6 +1287,30 @@ Properties of `params` object in errors depend on the keyword that failed valida - custom keywords (in case keyword definition doesn't create errors) - property `keyword` (the keyword name). +### Error Logging + +Using the `logger` option when initiallizing Ajv will allow you to define custom logging. Here you can build upon the exisiting logging. The use of other logging packages is supported as long as the package or its associated wrapper exposes the required methods. If any of the required methods are missing an exception will be thrown. +- **Required Methods**: `log`, `warn`, `error` + +```javascript +var otherLogger = new OtherLogger(); +var ajv = new Ajv({ + logger: { + log: function log(_log) { + return console.log(_log); + }, + warn: function warn(_warn) { + return otherLogger.logWarn(_warn); + }, + error: function error(_error) { + otherLogger.logError(_error); + return console.error(_error); + } + } +}); +``` + + ## Plugins Ajv can be extended with plugins that add custom keywords, formats or functions to process generated code. When such plugin is published as npm package it is recommended that it follows these conventions: From 46171d295dda49b6f68365665bbe8dedd34b6a66 Mon Sep 17 00:00:00 2001 From: Francisco Morais <35690067+franciscomorais@users.noreply.github.com> Date: Thu, 13 Feb 2020 14:16:31 +0000 Subject: [PATCH 21/32] Add keywords to ajv options --- lib/ajv.d.ts | 4 ++++ lib/ajv.js | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/ajv.d.ts b/lib/ajv.d.ts index 29cdee59a..cb600e168 100644 --- a/lib/ajv.d.ts +++ b/lib/ajv.d.ts @@ -171,6 +171,7 @@ declare namespace ajv { unicode?: boolean; format?: false | string; formats?: object; + keywords?: object; unknownFormats?: true | string[] | 'ignore'; schemas?: Array | object; schemaId?: '$id' | 'id' | 'auto'; @@ -252,6 +253,9 @@ declare namespace ajv { formats: { [index: string]: FormatDefinition | undefined; }; + keywords: { + [index: string]: KeywordDefinition | undefined; + }; compositeRule: boolean; validate: (schema: object) => boolean; util: { diff --git a/lib/ajv.js b/lib/ajv.js index 611b93835..06a45b650 100644 --- a/lib/ajv.js +++ b/lib/ajv.js @@ -69,6 +69,7 @@ function Ajv(opts) { this._metaOpts = getMetaSchemaOptions(this); if (opts.formats) addInitialFormats(this); + if (opts.keywords) addInitialKeywords(this); addDefaultMetaSchema(this); if (typeof opts.meta == 'object') this.addMetaSchema(opts.meta); if (opts.nullable) this.addKeyword('nullable', {metaSchema: {type: 'boolean'}}); @@ -467,6 +468,14 @@ function addInitialFormats(self) { } +function addInitialKeywords(self) { + for (var name in self._opts.keywords) { + var keyword = self._opts.keywords[name]; + self.addKeyword(name, keyword); + } +} + + function checkUnique(self, id) { if (self._schemas[id] || self._refs[id]) throw new Error('schema with key or id "' + id + '" already exists'); From 4d9dd8c2a69ef97949720bef50ba85074f0c9909 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sun, 16 Feb 2020 22:24:10 +0000 Subject: [PATCH 22/32] docs: link to $data reference proposal, closes #51 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d645c3f70..5569828aa 100644 --- a/README.md +++ b/README.md @@ -328,7 +328,7 @@ __Please note__: ## $data reference -With `$data` option you can use values from the validated data as the values for the schema keywords. See [proposal](https://github.com/json-schema/json-schema/wiki/$data-(v5-proposal)) for more information about how it works. +With `$data` option you can use values from the validated data as the values for the schema keywords. See [proposal](https://github.com/json-schema-org/json-schema-spec/issues/51) for more information about how it works. `$data` reference is supported in the keywords: const, enum, format, maximum/minimum, exclusiveMaximum / exclusiveMinimum, maxLength / minLength, maxItems / minItems, maxProperties / minProperties, formatMaximum / formatMinimum, formatExclusiveMaximum / formatExclusiveMinimum, multipleOf, pattern, required, uniqueItems. From 120748cc6cfa2366167b2da93ad34d1db69088fc Mon Sep 17 00:00:00 2001 From: sambauers Date: Mon, 17 Feb 2020 10:23:34 +1100 Subject: [PATCH 23/32] Only use regex for hostname checks. --- lib/compile/formats.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/compile/formats.js b/lib/compile/formats.js index 0e6e910fa..44895b0b4 100644 --- a/lib/compile/formats.js +++ b/lib/compile/formats.js @@ -70,7 +70,7 @@ formats.full = { 'uri-template': URITEMPLATE, url: URL, email: /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i, - hostname: hostname, + hostname: HOSTNAME, ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/, ipv6: /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i, regex: regex, @@ -123,15 +123,6 @@ function date_time(str) { } -function hostname(str) { - // https://tools.ietf.org/html/rfc1034#section-3.5 - // https://tools.ietf.org/html/rfc1123#section-2 - // https://devblogs.microsoft.com/oldnewthing/?p=7873 - // https://tools.ietf.org/html/rfc1034#section-3.1 - return HOSTNAME.test(str); -} - - var NOT_URI_FRAGMENT = /\/|:/; function uri(str) { // http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + optional protocol + required "." From f94db48984da812306acd8c080778807af514ede Mon Sep 17 00:00:00 2001 From: Francisco Morais <35690067+franciscomorais@users.noreply.github.com> Date: Thu, 13 Feb 2020 14:16:56 +0000 Subject: [PATCH 24/32] Update options validation spec --- spec/options/options_validation.spec.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/options/options_validation.spec.js b/spec/options/options_validation.spec.js index e362826bc..3f86b2fc7 100644 --- a/spec/options/options_validation.spec.js +++ b/spec/options/options_validation.spec.js @@ -26,12 +26,35 @@ describe('validation options', function() { }}); var validate = ajv.compile({ format: 'identifier' }); + validate('Abc1') .should.equal(true); validate('123') .should.equal(false); validate(123) .should.equal(true); }); }); + describe('keywords', function() { + it('should add keywords from options', function() { + var ajv = new Ajv({ keywords: { + string: { + validate: function (schema, data ) { + + console.log(">>", data); + return /^[a-z_$][a-z0-9_$]*$/i.test(data); + } + } + }}); + + var validate = ajv.compile({ string: true }); + + validate('Abc1') .should.equal(true); + validate('foo bar').should.equal(false); + validate('123').should.equal(false); + validate(123).should.equal(false); + validate(123).should.equal(false); + }); + }); + describe('uniqueItems', function() { it('should not validate uniqueItems with uniqueItems option == false', function() { From 38191c2693ccb06ab2d79b24c6ca9aa29a4d2c03 Mon Sep 17 00:00:00 2001 From: Francisco Morais <35690067+franciscomorais@users.noreply.github.com> Date: Thu, 13 Feb 2020 14:17:10 +0000 Subject: [PATCH 25/32] Update readme with keywords option --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d645c3f70..cc6992d4d 100644 --- a/README.md +++ b/README.md @@ -1144,6 +1144,7 @@ Defaults: - `"full"` - more restrictive and slow validation. E.g., 25:00:00 and 2015/14/33 will be invalid time and date in 'full' mode but it will be valid in 'fast' mode. - `false` - ignore all format keywords. - _formats_: an object with custom formats. Keys and values will be passed to `addFormat` method. +- _keywords_: an object with custom keywords. Keys and values will be passed to `addKeyword` method. - _unknownFormats_: handling of unknown formats. Option values: - `true` (default) - if an unknown format is encountered the exception is thrown during schema compilation. If `format` keyword value is [$data reference](#data-reference) and it is unknown the validation will fail. - `[String]` - an array of unknown format names that will be ignored. This option can be used to allow usage of third party schemas with format(s) for which you don't have definitions, but still fail if another unknown format is used. If `format` keyword value is [$data reference](#data-reference) and it is not in this array the validation will fail. From e5bed30f2a057227ec4c256588906e220c4c302b Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 22 Feb 2020 13:14:51 +0000 Subject: [PATCH 26/32] test: update option keywords test --- spec/options/options_validation.spec.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/spec/options/options_validation.spec.js b/spec/options/options_validation.spec.js index 3f86b2fc7..950a0c289 100644 --- a/spec/options/options_validation.spec.js +++ b/spec/options/options_validation.spec.js @@ -28,6 +28,7 @@ describe('validation options', function() { var validate = ajv.compile({ format: 'identifier' }); validate('Abc1') .should.equal(true); + validate('foo bar') .should.equal(false); validate('123') .should.equal(false); validate(123) .should.equal(true); }); @@ -36,22 +37,20 @@ describe('validation options', function() { describe('keywords', function() { it('should add keywords from options', function() { var ajv = new Ajv({ keywords: { - string: { + identifier: { + type: 'string', validate: function (schema, data ) { - - console.log(">>", data); return /^[a-z_$][a-z0-9_$]*$/i.test(data); } } }}); - var validate = ajv.compile({ string: true }); + var validate = ajv.compile({ identifier: true }); validate('Abc1') .should.equal(true); - validate('foo bar').should.equal(false); - validate('123').should.equal(false); - validate(123).should.equal(false); - validate(123).should.equal(false); + validate('foo bar') .should.equal(false); + validate('123') .should.equal(false); + validate(123) .should.equal(true); }); }); From 0163e5c233bc9d6d2795cd498719c568d4a8653a Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 22 Feb 2020 13:29:55 +0000 Subject: [PATCH 27/32] docs: error logging code sample --- README.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index bc245a313..9bd1f5718 100644 --- a/README.md +++ b/README.md @@ -1158,7 +1158,7 @@ Defaults: - `[String]` - an array of unknown format names that will be ignored. This option can be used to allow usage of third party schemas with format(s) for which you don't have definitions, but still fail if another unknown format is used. If `format` keyword value is [$data reference](#data-reference) and it is not in this array the validation will fail. - `"ignore"` - to log warning during schema compilation and always pass validation (the default behaviour in versions before 5.0.0). This option is not recommended, as it allows to mistype format name and it won't be validated without any error message. This behaviour is required by JSON Schema specification. - _schemas_: an array or object of schemas that will be added to the instance. In case you pass the array the schemas must have IDs in them. When the object is passed the method `addSchema(value, key)` will be called for each schema in this object. -- _logger_: sets the logging method. Default is the global `console` object that should have methods `log`, `warn` and `error`. Option values: +- _logger_: sets the logging method. Default is the global `console` object that should have methods `log`, `warn` and `error`. See [Error logging](#error-logging). Option values: - custom logger - it should have methods `log`, `warn` and `error`. If any of these methods is missing an exception will be thrown. - `false` - logging is disabled. @@ -1296,7 +1296,7 @@ Properties of `params` object in errors depend on the keyword that failed valida - custom keywords (in case keyword definition doesn't create errors) - property `keyword` (the keyword name). -### Error Logging +### Error logging Using the `logger` option when initiallizing Ajv will allow you to define custom logging. Here you can build upon the exisiting logging. The use of other logging packages is supported as long as the package or its associated wrapper exposes the required methods. If any of the required methods are missing an exception will be thrown. - **Required Methods**: `log`, `warn`, `error` @@ -1305,15 +1305,13 @@ Using the `logger` option when initiallizing Ajv will allow you to define custom var otherLogger = new OtherLogger(); var ajv = new Ajv({ logger: { - log: function log(_log) { - return console.log(_log); + log: console.log.bind(console), + warn: function warn() { + otherLogger.logWarn.apply(otherLogger, arguments); }, - warn: function warn(_warn) { - return otherLogger.logWarn(_warn); - }, - error: function error(_error) { - otherLogger.logError(_error); - return console.error(_error); + error: function error() { + otherLogger.logError.apply(otherLogger, arguments); + console.error.apply(console, arguments); } } }); From 03d0012f0cf35a834933de07d79522fe7ec9e90a Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 22 Feb 2020 13:40:26 +0000 Subject: [PATCH 28/32] 6.12.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5cfec97d2..419583ece 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv", - "version": "6.11.0", + "version": "6.12.0", "description": "Another JSON Schema Validator", "main": "lib/ajv.js", "typings": "lib/ajv.d.ts", From b15a73cdc1c1b0bd1859f3f26193c22101f51fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quin=CC=83o=CC=81nez=2C=20Carlo=20J?= Date: Thu, 23 Jan 2020 16:15:53 -0800 Subject: [PATCH 29/32] Add to README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d645c3f70..544b25aa3 100644 --- a/README.md +++ b/README.md @@ -1309,7 +1309,7 @@ If you have published a useful plugin please submit a PR to add it to the next s - [ajv-keywords](https://github.com/epoberezkin/ajv-keywords) - plugin with custom validation keywords (select, typeof, etc.) - [ajv-merge-patch](https://github.com/epoberezkin/ajv-merge-patch) - plugin with keywords $merge and $patch - [ajv-pack](https://github.com/epoberezkin/ajv-pack) - produces a compact module exporting validation functions - +- [ajv-formats-draft2019](https://github.com/luzlab/ajv-formats-draft2019) - format validators for draft2019 that aren't already included in ajv (ie. `idn-hostname`, `idn-email`, `iri`, `iri-reference` and `duration`). ## Some packages using Ajv From 0775bc1a6c5c313138373a2047b1b8772128873f Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sun, 22 Mar 2020 11:38:03 +0000 Subject: [PATCH 30/32] Update FUNDING.yml --- .github/FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index c77c8e485..5dcdc3e50 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,2 +1,2 @@ +github: epoberezkin tidelift: "npm/ajv" -open_collective: "ajv" From 9f5752c1ff4b3cb5f078c4bccbc464a97828397f Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sat, 4 Apr 2020 22:54:06 +0100 Subject: [PATCH 31/32] docs: sponsor --- README.md | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e7450b4a..788298b22 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,49 @@ The fastest JSON Schema validator for Node.js and browser. Supports draft-04/06/ [![npm](https://img.shields.io/npm/v/ajv.svg)](https://www.npmjs.com/package/ajv) [![npm downloads](https://img.shields.io/npm/dm/ajv.svg)](https://www.npmjs.com/package/ajv) [![Coverage Status](https://coveralls.io/repos/epoberezkin/ajv/badge.svg?branch=master&service=github)](https://coveralls.io/github/epoberezkin/ajv?branch=master) -[![Greenkeeper badge](https://badges.greenkeeper.io/epoberezkin/ajv.svg)](https://greenkeeper.io/) [![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv) +[![GitHub Sponsors](https://img.shields.io/badge/$-sponsors-brightgreen)](https://github.com/sponsors/epoberezkin) + +## Please sponsor Ajv development + +Dear Ajv users! ❤️ + +I ask you to support the development of Ajv with donations. 🙏 + +Since 2015 Ajv has become widely used, thanks to your help and contributions: + +- **90** contributors 🏗 +- **5,000** dependent npm packages ⚙️ +- **7,000** github stars, from GitHub users [all over the world](https://www.google.com/maps/d/u/0/viewer?mid=1MGRV8ciFUGIbO1l0EKFWNJGYE7iSkDxP&ll=-3.81666561775622e-14%2C4.821737100000007&z=2) ⭐️ +- **5,000,000** dependent repositories on GitHub 🚀 +- **120,000,000** npm downloads per month! 💯 + +Your donations will fund futher development - small and large improvements, support of the next versions of JSON Schema specification, and, possibly, the code should be migrated to TypeScript to make it more maintainable. + +I will greatly appreciate anything you can help with to make it happen: + +- a **personal** donation - from $2 ☕️ +- your **company** donation - from $10 🍔 +- a **sponsorship** to get promoted on Ajv or related packages - from $50 💰 +- an **introduction** to a sponsor who would benefit from the promotion on Ajv page 🤝 + +| ‼️ Please make donations via [my GitHub sponsors page](https://github.com/sponsors/epoberezkin) - **GitHub pledged to DOUBLE them** ‼️ | +|---| + +#### Open Collective sponsors + + + + + + + + + + + + + ## Using version 6 From 081aeb0cd1b07e9a0f55b3226f1855062ba78cd9 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 5 Apr 2020 13:39:40 +0100 Subject: [PATCH 32/32] docs: readme, open collective --- .github/FUNDING.yml | 1 + README.md | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 5dcdc3e50..88fc551fa 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,2 +1,3 @@ github: epoberezkin tidelift: "npm/ajv" +open_collective: "ajv" diff --git a/README.md b/README.md index 788298b22..844dcb6cd 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ The fastest JSON Schema validator for Node.js and browser. Supports draft-04/06/ [![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv) [![GitHub Sponsors](https://img.shields.io/badge/$-sponsors-brightgreen)](https://github.com/sponsors/epoberezkin) -## Please sponsor Ajv development +## Please [sponsor Ajv](https://github.com/sponsors/epoberezkin) Dear Ajv users! ❤️ @@ -34,7 +34,7 @@ I will greatly appreciate anything you can help with to make it happen: - a **sponsorship** to get promoted on Ajv or related packages - from $50 💰 - an **introduction** to a sponsor who would benefit from the promotion on Ajv page 🤝 -| ‼️ Please make donations via [my GitHub sponsors page](https://github.com/sponsors/epoberezkin) - **GitHub pledged to DOUBLE them** ‼️ | +| Please [make donations via my GitHub sponsors page](https://github.com/sponsors/epoberezkin)
‼️ **GitHub will DOUBLE them** ‼️ | |---| #### Open Collective sponsors