From a37ed7dc6fd4685e53fadc1fce195d2e1420f70e Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Tue, 11 Dec 2018 17:30:16 +0000 Subject: [PATCH 1/6] chore(package): update karma-sauce-launcher to version 2.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0646971..eeb4e49 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "karma": "^3.0.0", "karma-chrome-launcher": "^2.2.0", "karma-mocha": "^1.1.1", - "karma-sauce-launcher": "^1.1.0", + "karma-sauce-launcher": "^2.0.0", "mocha": "^5.1.1", "nyc": "^12.0.1", "pre-commit": "^1.1.1", From 3df9b7302f3b8495bb28d04eb1bbf6098a04f1f6 Mon Sep 17 00:00:00 2001 From: xdu Date: Fri, 14 Dec 2018 23:46:47 -0800 Subject: [PATCH 2/6] Adding example to load official draft-04 to README --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 44b5081..39909cb 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,21 @@ var ajv = new Ajv({schemaId: 'id'}); ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json')); ``` +In case the above meta schema gives you validation error on `id` or `$schema` see [issue](https://github.com/epoberezkin/ajv/issues/904) you can load the official meta schema json instead. Example with `axios` (feel free to replace `axios` with the your preferred http request package): + +```javascript +// inside an async function. +const axios = require('axios'); +const util = require('util'); + +const response = await axios.get('http://json-schema.org/draft-04/schema#'); +if (response.status != 200) { + throw new Error(util.format('could not load draft-04 schema. status=%s', response.status)); +} + +ajv.addMetaSchema(response.data); +``` + ## Contents From 8f24e34158b1057771ac07fc5c19ff7557d2d340 Mon Sep 17 00:00:00 2001 From: Xing Du Date: Sat, 15 Dec 2018 19:10:57 -0800 Subject: [PATCH 3/6] Replace lib/refs/json-schema-draft-04.json with a copy of the official one And revert the previous README change --- README.md | 15 --------------- lib/refs/json-schema-draft-04.json | 7 +++---- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 39909cb..44b5081 100644 --- a/README.md +++ b/README.md @@ -34,21 +34,6 @@ var ajv = new Ajv({schemaId: 'id'}); ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json')); ``` -In case the above meta schema gives you validation error on `id` or `$schema` see [issue](https://github.com/epoberezkin/ajv/issues/904) you can load the official meta schema json instead. Example with `axios` (feel free to replace `axios` with the your preferred http request package): - -```javascript -// inside an async function. -const axios = require('axios'); -const util = require('util'); - -const response = await axios.get('http://json-schema.org/draft-04/schema#'); -if (response.status != 200) { - throw new Error(util.format('could not load draft-04 schema. status=%s', response.status)); -} - -ajv.addMetaSchema(response.data); -``` - ## Contents diff --git a/lib/refs/json-schema-draft-04.json b/lib/refs/json-schema-draft-04.json index 85eb502..bcbb847 100644 --- a/lib/refs/json-schema-draft-04.json +++ b/lib/refs/json-schema-draft-04.json @@ -28,12 +28,10 @@ "type": "object", "properties": { "id": { - "type": "string", - "format": "uri" + "type": "string" }, "$schema": { - "type": "string", - "format": "uri" + "type": "string" }, "title": { "type": "string" @@ -137,6 +135,7 @@ } ] }, + "format": { "type": "string" }, "allOf": { "$ref": "#/definitions/schemaArray" }, "anyOf": { "$ref": "#/definitions/schemaArray" }, "oneOf": { "$ref": "#/definitions/schemaArray" }, From 223058beb07e46ede4b8e344361b696069b9ba95 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 16 Dec 2018 20:46:30 +0000 Subject: [PATCH 4/6] refactor: remove uri format change during schema validation, closes #906 --- lib/ajv.js | 10 +--------- spec/options.spec.js | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/ajv.js b/lib/ajv.js index 9f16723..7a83e3b 100644 --- a/lib/ajv.js +++ b/lib/ajv.js @@ -55,8 +55,6 @@ function Ajv(opts) { this._refs = {}; this._fragments = {}; this._formats = formats(opts.format); - var schemaUriFormat = this._schemaUriFormat = this._formats['uri-reference']; - this._schemaUriFormatFunc = function (str) { return schemaUriFormat.test(str); }; this._cache = opts.cache || new Cache; this._loadingSchemas = {}; @@ -171,13 +169,7 @@ function validateSchema(schema, throwOrLogError) { this.errors = null; return true; } - var currentUriFormat = this._formats.uri; - this._formats.uri = typeof currentUriFormat == 'function' - ? this._schemaUriFormatFunc - : this._schemaUriFormat; - var valid; - try { valid = this.validate($schema, schema); } - finally { this._formats.uri = currentUriFormat; } + var valid = this.validate($schema, schema); if (!valid && throwOrLogError) { var message = 'schema is invalid: ' + this.errorsText(); if (this._opts.validateSchema == 'log') this.logger.error(message); diff --git a/spec/options.spec.js b/spec/options.spec.js index 00d8392..1754fa8 100644 --- a/spec/options.spec.js +++ b/spec/options.spec.js @@ -1194,7 +1194,7 @@ describe('Ajv Options', function () { describe('= "id"', function() { it('should use id and ignore $id', function() { var ajv = new Ajv({schemaId: 'id', meta: false}); - ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json')); + ajv.addMetaSchema(require('../lib/refs/json-schema-draft-04.json')); ajv._opts.defaultMeta = 'http://json-schema.org/draft-04/schema#'; ajv.addSchema({ id: 'mySchema1', type: 'string' }); From b4c0af9d299ff8892811723b0f98ef8eee816024 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 16 Dec 2018 20:49:44 +0000 Subject: [PATCH 5/6] docs: mark url format as deprecated --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 44b5081..15b1e6a 100644 --- a/README.md +++ b/README.md @@ -244,7 +244,7 @@ The following formats are supported for string validation with "format" keyword: - _uri_: full URI. - _uri-reference_: URI reference, including full and relative URIs. - _uri-template_: URI template according to [RFC6570](https://tools.ietf.org/html/rfc6570) -- _url_: [URL record](https://url.spec.whatwg.org/#concept-url). +- _url_ (deprecated): [URL record](https://url.spec.whatwg.org/#concept-url). - _email_: email address. - _hostname_: host name according to [RFC1034](http://tools.ietf.org/html/rfc1034#section-3.5). - _ipv4_: IP address v4. From 78b77b67290f6cafb2066e2a0e8681d81ca74b0c Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 16 Dec 2018 20:54:54 +0000 Subject: [PATCH 6/6] 6.6.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eeb4e49..0388bd2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv", - "version": "6.6.1", + "version": "6.6.2", "description": "Another JSON Schema Validator", "main": "lib/ajv.js", "typings": "lib/ajv.d.ts",