From a884acc6391ac034c598e3bbb84af8cc2bf7b451 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 28 Jan 2017 16:11:45 +0000 Subject: [PATCH 1/5] draft-04/06: base URI change tests --- tests/draft4/refRemote.json | 68 +++++++++++++++++++++++++++++++++++-- tests/draft6/refRemote.json | 68 +++++++++++++++++++++++++++++++++++-- 2 files changed, 130 insertions(+), 6 deletions(-) diff --git a/tests/draft4/refRemote.json b/tests/draft4/refRemote.json index 4ca80473..4279dd20 100644 --- a/tests/draft4/refRemote.json +++ b/tests/draft4/refRemote.json @@ -50,7 +50,7 @@ ] }, { - "description": "change resolution scope", + "description": "base URI change", "schema": { "id": "http://localhost:1234/", "items": { @@ -60,15 +60,77 @@ }, "tests": [ { - "description": "changed scope ref valid", + "description": "base URI change ref valid", "data": [[1]], "valid": true }, { - "description": "changed scope ref invalid", + "description": "base URI change ref invalid", "data": [["a"]], "valid": false } ] + }, + { + "description": "base URI change - change folder", + "schema": { + "id": "http://localhost:1234/scope_change_defs1.json", + "type" : "object", + "properties": { + "list": {"$ref": "#/definitions/baz"} + }, + "definitions": { + "baz": { + "id": "folder/", + "type": "array", + "items": {"$ref": "folderInteger.json"} + } + } + }, + "tests": [ + { + "description": "number is valid", + "data": {"list": [1]}, + "valid": true + }, + { + "description": "string is invalid", + "data": {"list": ["a"]}, + "valid": false + } + ] + }, + { + "description": "base URI change - change folder in subschema", + "schema": { + "id": "http://localhost:1234/scope_change_defs2.json", + "type" : "object", + "properties": { + "list": {"$ref": "#/definitions/baz/definitions/bar"} + }, + "definitions": { + "baz": { + "id": "folder/", + "definitions": { + "bar": { + "type": "array", + "items": {"$ref": "folderInteger.json"} + } + } + } + } + }, + "tests": [ + { + "description": "number is valid", + "data": {"list": [1]}, + "valid": true + }, + { + "description": "string is invalid", + "data": {"list": ["a"]}, + "valid": false + } + ] } ] diff --git a/tests/draft6/refRemote.json b/tests/draft6/refRemote.json index 4ca80473..4279dd20 100644 --- a/tests/draft6/refRemote.json +++ b/tests/draft6/refRemote.json @@ -50,7 +50,7 @@ ] }, { - "description": "change resolution scope", + "description": "base URI change", "schema": { "id": "http://localhost:1234/", "items": { @@ -60,15 +60,77 @@ }, "tests": [ { - "description": "changed scope ref valid", + "description": "base URI change ref valid", "data": [[1]], "valid": true }, { - "description": "changed scope ref invalid", + "description": "base URI change ref invalid", "data": [["a"]], "valid": false } ] + }, + { + "description": "base URI change - change folder", + "schema": { + "id": "http://localhost:1234/scope_change_defs1.json", + "type" : "object", + "properties": { + "list": {"$ref": "#/definitions/baz"} + }, + "definitions": { + "baz": { + "id": "folder/", + "type": "array", + "items": {"$ref": "folderInteger.json"} + } + } + }, + "tests": [ + { + "description": "number is valid", + "data": {"list": [1]}, + "valid": true + }, + { + "description": "string is invalid", + "data": {"list": ["a"]}, + "valid": false + } + ] + }, + { + "description": "base URI change - change folder in subschema", + "schema": { + "id": "http://localhost:1234/scope_change_defs2.json", + "type" : "object", + "properties": { + "list": {"$ref": "#/definitions/baz/definitions/bar"} + }, + "definitions": { + "baz": { + "id": "folder/", + "definitions": { + "bar": { + "type": "array", + "items": {"$ref": "folderInteger.json"} + } + } + } + } + }, + "tests": [ + { + "description": "number is valid", + "data": {"list": [1]}, + "valid": true + }, + { + "description": "string is invalid", + "data": {"list": ["a"]}, + "valid": false + } + ] } ] From 0178c74c894f6b1a2f7c9ac6f9b60da44e786b6f Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 28 Jan 2017 16:26:09 +0000 Subject: [PATCH 2/5] draft-04/06: recursive refs test --- tests/draft4/ref.json | 88 +++++++++++++++++++++++++++++++++++++++++++ tests/draft6/ref.json | 88 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+) diff --git a/tests/draft4/ref.json b/tests/draft4/ref.json index e9867a8d..52cf50a9 100644 --- a/tests/draft4/ref.json +++ b/tests/draft4/ref.json @@ -208,5 +208,93 @@ "valid": false } ] + }, + { + "description": "Recursive references between schemas", + "schema": { + "id": "http://localhost:1234/tree", + "description": "tree of nodes", + "type": "object", + "properties": { + "meta": {"type": "string"}, + "nodes": { + "type": "array", + "items": {"$ref": "node"} + } + }, + "required": ["meta", "nodes"], + "definitions": { + "node": { + "id": "http://localhost:1234/node", + "description": "node", + "type": "object", + "properties": { + "value": {"type": "number"}, + "subtree": {"$ref": "tree"} + }, + "required": ["value"] + } + } + }, + "tests": [ + { + "description": "valid tree", + "data": { + "meta": "root", + "nodes": [ + { + "value": 1, + "subtree": { + "meta": "child", + "nodes": [ + {"value": 1.1}, + {"value": 1.2} + ] + } + }, + { + "value": 2, + "subtree": { + "meta": "child", + "nodes": [ + {"value": 2.1}, + {"value": 2.2} + ] + } + } + ] + }, + "valid": true + }, + { + "description": "invalid tree", + "data": { + "meta": "root", + "nodes": [ + { + "value": 1, + "subtree": { + "meta": "child", + "nodes": [ + {"value": "string is invalid"}, + {"value": 1.2} + ] + } + }, + { + "value": 2, + "subtree": { + "meta": "child", + "nodes": [ + {"value": 2.1}, + {"value": 2.2} + ] + } + } + ] + }, + "valid": false + } + ] } ] diff --git a/tests/draft6/ref.json b/tests/draft6/ref.json index e9867a8d..52cf50a9 100644 --- a/tests/draft6/ref.json +++ b/tests/draft6/ref.json @@ -208,5 +208,93 @@ "valid": false } ] + }, + { + "description": "Recursive references between schemas", + "schema": { + "id": "http://localhost:1234/tree", + "description": "tree of nodes", + "type": "object", + "properties": { + "meta": {"type": "string"}, + "nodes": { + "type": "array", + "items": {"$ref": "node"} + } + }, + "required": ["meta", "nodes"], + "definitions": { + "node": { + "id": "http://localhost:1234/node", + "description": "node", + "type": "object", + "properties": { + "value": {"type": "number"}, + "subtree": {"$ref": "tree"} + }, + "required": ["value"] + } + } + }, + "tests": [ + { + "description": "valid tree", + "data": { + "meta": "root", + "nodes": [ + { + "value": 1, + "subtree": { + "meta": "child", + "nodes": [ + {"value": 1.1}, + {"value": 1.2} + ] + } + }, + { + "value": 2, + "subtree": { + "meta": "child", + "nodes": [ + {"value": 2.1}, + {"value": 2.2} + ] + } + } + ] + }, + "valid": true + }, + { + "description": "invalid tree", + "data": { + "meta": "root", + "nodes": [ + { + "value": 1, + "subtree": { + "meta": "child", + "nodes": [ + {"value": "string is invalid"}, + {"value": 1.2} + ] + } + }, + { + "value": 2, + "subtree": { + "meta": "child", + "nodes": [ + {"value": 2.1}, + {"value": 2.2} + ] + } + } + ] + }, + "valid": false + } + ] } ] From 3186761b2075a674e0b6667624f9563dc9f8261c Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 28 Jan 2017 16:55:57 +0000 Subject: [PATCH 3/5] draft-04/06: root ref "#" in remote ref --- remotes/name.json | 11 +++++++++++ tests/draft4/refRemote.json | 35 +++++++++++++++++++++++++++++++++++ tests/draft6/refRemote.json | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 remotes/name.json diff --git a/remotes/name.json b/remotes/name.json new file mode 100644 index 00000000..19ba0935 --- /dev/null +++ b/remotes/name.json @@ -0,0 +1,11 @@ +{ + "definitions": { + "orNull": { + "anyOf": [ + {"type": "null"}, + {"$ref": "#"} + ] + } + }, + "type": "string" +} diff --git a/tests/draft4/refRemote.json b/tests/draft4/refRemote.json index 4279dd20..8611fadc 100644 --- a/tests/draft4/refRemote.json +++ b/tests/draft4/refRemote.json @@ -132,5 +132,40 @@ "valid": false } ] + }, + { + "description": "root ref in remote ref", + "schema": { + "id": "http://localhost:1234/object", + "type": "object", + "properties": { + "name": {"$ref": "name.json#/definitions/orNull"} + } + }, + "tests": [ + { + "description": "string is valid", + "data": { + "name": "foo" + }, + "valid": true + }, + { + "description": "null is valid", + "data": { + "name": null + }, + "valid": true + }, + { + "description": "object is invalid", + "data": { + "name": { + "name": null + } + }, + "valid": false + } + ] } ] diff --git a/tests/draft6/refRemote.json b/tests/draft6/refRemote.json index 4279dd20..8611fadc 100644 --- a/tests/draft6/refRemote.json +++ b/tests/draft6/refRemote.json @@ -132,5 +132,40 @@ "valid": false } ] + }, + { + "description": "root ref in remote ref", + "schema": { + "id": "http://localhost:1234/object", + "type": "object", + "properties": { + "name": {"$ref": "name.json#/definitions/orNull"} + } + }, + "tests": [ + { + "description": "string is valid", + "data": { + "name": "foo" + }, + "valid": true + }, + { + "description": "null is valid", + "data": { + "name": null + }, + "valid": true + }, + { + "description": "object is invalid", + "data": { + "name": { + "name": null + } + }, + "valid": false + } + ] } ] From 671bad6f2f10c2734baba280934bd651b82f1d92 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Mon, 13 Mar 2017 21:59:50 +0000 Subject: [PATCH 4/5] fix: JavaScript test --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 9d332c78..6a3143b3 100644 --- a/index.js +++ b/index.js @@ -7,14 +7,15 @@ var assert = require('assert'); var refs = { 'http://localhost:1234/integer.json': require('./remotes/integer.json'), 'http://localhost:1234/subSchemas.json': require('./remotes/subSchemas.json'), - 'http://localhost:1234/folder/folderInteger.json': require('./remotes/folder/folderInteger.json') + 'http://localhost:1234/folder/folderInteger.json': require('./remotes/folder/folderInteger.json'), + 'http://localhost:1234/name.json': require('./remotes/name.json') }; runTest(4); runTest(6); function runTest(draft) { - var opts = {addUsedSchema: false}; + var opts = {}; if (draft == 4) opts.meta = false; var ajv = new Ajv(opts); ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json')); From 25836f75815f480930babed647f686fd7d27f091 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Mon, 13 Mar 2017 22:02:45 +0000 Subject: [PATCH 5/5] update draft-06 tests: "id" -> "$id" --- tests/draft6/ref.json | 4 ++-- tests/draft6/refRemote.json | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/draft6/ref.json b/tests/draft6/ref.json index 5e6ada27..6dcf6cd8 100644 --- a/tests/draft6/ref.json +++ b/tests/draft6/ref.json @@ -244,7 +244,7 @@ { "description": "Recursive references between schemas", "schema": { - "id": "http://localhost:1234/tree", + "$id": "http://localhost:1234/tree", "description": "tree of nodes", "type": "object", "properties": { @@ -257,7 +257,7 @@ "required": ["meta", "nodes"], "definitions": { "node": { - "id": "http://localhost:1234/node", + "$id": "http://localhost:1234/node", "description": "node", "type": "object", "properties": { diff --git a/tests/draft6/refRemote.json b/tests/draft6/refRemote.json index 0844f125..819d3267 100644 --- a/tests/draft6/refRemote.json +++ b/tests/draft6/refRemote.json @@ -74,14 +74,14 @@ { "description": "base URI change - change folder", "schema": { - "id": "http://localhost:1234/scope_change_defs1.json", + "$id": "http://localhost:1234/scope_change_defs1.json", "type" : "object", "properties": { "list": {"$ref": "#/definitions/baz"} }, "definitions": { "baz": { - "id": "folder/", + "$id": "folder/", "type": "array", "items": {"$ref": "folderInteger.json"} } @@ -103,14 +103,14 @@ { "description": "base URI change - change folder in subschema", "schema": { - "id": "http://localhost:1234/scope_change_defs2.json", + "$id": "http://localhost:1234/scope_change_defs2.json", "type" : "object", "properties": { "list": {"$ref": "#/definitions/baz/definitions/bar"} }, "definitions": { "baz": { - "id": "folder/", + "$id": "folder/", "definitions": { "bar": { "type": "array", @@ -136,7 +136,7 @@ { "description": "root ref in remote ref", "schema": { - "id": "http://localhost:1234/object", + "$id": "http://localhost:1234/object", "type": "object", "properties": { "name": {"$ref": "name.json#/definitions/orNull"}