summaryrefslogtreecommitdiff
path: root/json
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2020-03-04 15:40:25 -0500
committerJulian Berman <Julian@GrayVines.com>2020-03-04 15:40:25 -0500
commit2ab84f8410a7dc9c8c266646cb2784b1d378165f (patch)
tree76827e08ca71db651ab5024429c17818b39564cd /json
parent5f908e41b3f423bd4b38300dfc3bb7d9a15be21d (diff)
parent11df97257859996434f37e33ad3d8cf2bd3606da (diff)
downloadjsonschema-2ab84f8410a7dc9c8c266646cb2784b1d378165f.tar.gz
Merge commit '11df97257859996434f37e33ad3d8cf2bd3606da'
* commit '11df97257859996434f37e33ad3d8cf2bd3606da': Squashed 'json/' changes from d52866b3..b70c5626
Diffstat (limited to 'json')
-rwxr-xr-xjson/bin/jsonschema_suite6
-rw-r--r--json/remotes/subSchemas-defs.json10
-rw-r--r--json/tests/draft2019-09/dependencies.json250
-rw-r--r--json/tests/draft2019-09/dependentRequired.json142
-rw-r--r--json/tests/draft2019-09/dependentSchemas.json114
-rw-r--r--json/tests/draft2019-09/ref.json14
-rw-r--r--json/tests/draft2019-09/refRemote.json8
-rw-r--r--json/tests/draft2019-09/unevaluatedItems.json87
-rw-r--r--json/tests/draft2019-09/unevaluatedProperties.json80
9 files changed, 440 insertions, 271 deletions
diff --git a/json/bin/jsonschema_suite b/json/bin/jsonschema_suite
index 36bb2dd..c8bb7ba 100755
--- a/json/bin/jsonschema_suite
+++ b/json/bin/jsonschema_suite
@@ -45,6 +45,12 @@ REMOTES = {
u"integer": {u"type": u"integer"},
u"refToInteger": {u"$ref": u"#/integer"},
},
+ "subSchemas-defs.json": {
+ u"$defs": {
+ u"integer": {u"type": u"integer"},
+ u"refToInteger": {u"$ref": u"#/$defs/integer"},
+ }
+ },
"folder/folderInteger.json": {u"type": u"integer"}
}
REMOTES_DIR = os.path.join(ROOT_DIR, "remotes")
diff --git a/json/remotes/subSchemas-defs.json b/json/remotes/subSchemas-defs.json
new file mode 100644
index 0000000..50b7b6d
--- /dev/null
+++ b/json/remotes/subSchemas-defs.json
@@ -0,0 +1,10 @@
+{
+ "$defs": {
+ "integer": {
+ "type": "integer"
+ },
+ "refToInteger": {
+ "$ref": "#/$defs/integer"
+ }
+ }
+}
diff --git a/json/tests/draft2019-09/dependencies.json b/json/tests/draft2019-09/dependencies.json
deleted file mode 100644
index b82b5a9..0000000
--- a/json/tests/draft2019-09/dependencies.json
+++ /dev/null
@@ -1,250 +0,0 @@
-[
- {
- "description": "dependentRequired",
- "schema": {
- "dependentRequired": {"bar": ["foo"]}
- },
- "tests": [
- {
- "description": "neither",
- "data": {},
- "valid": true
- },
- {
- "description": "nondependant",
- "data": {"foo": 1},
- "valid": true
- },
- {
- "description": "with dependency",
- "data": {"foo": 1, "bar": 2},
- "valid": true
- },
- {
- "description": "missing dependency",
- "data": {"bar": 2},
- "valid": false
- },
- {
- "description": "ignores arrays",
- "data": ["bar"],
- "valid": true
- },
- {
- "description": "ignores strings",
- "data": "foobar",
- "valid": true
- },
- {
- "description": "ignores other non-objects",
- "data": 12,
- "valid": true
- }
- ]
- },
- {
- "description": "dependentRequired with empty array",
- "schema": {
- "dependentRequired": {"bar": []}
- },
- "tests": [
- {
- "description": "empty object",
- "data": {},
- "valid": true
- },
- {
- "description": "object with one property",
- "data": {"bar": 2},
- "valid": true
- },
- {
- "description": "non-object is valid",
- "data": 1,
- "valid": true
- }
- ]
- },
- {
- "description": "multiple dependents required",
- "schema": {
- "dependentRequired": {"quux": ["foo", "bar"]}
- },
- "tests": [
- {
- "description": "neither",
- "data": {},
- "valid": true
- },
- {
- "description": "nondependants",
- "data": {"foo": 1, "bar": 2},
- "valid": true
- },
- {
- "description": "with dependencies",
- "data": {"foo": 1, "bar": 2, "quux": 3},
- "valid": true
- },
- {
- "description": "missing dependency",
- "data": {"foo": 1, "quux": 2},
- "valid": false
- },
- {
- "description": "missing other dependency",
- "data": {"bar": 1, "quux": 2},
- "valid": false
- },
- {
- "description": "missing both dependencies",
- "data": {"quux": 1},
- "valid": false
- }
- ]
- },
- {
- "description": "multiple dependentSchemas subschema",
- "schema": {
- "dependentSchemas": {
- "bar": {
- "properties": {
- "foo": {"type": "integer"},
- "bar": {"type": "integer"}
- }
- }
- }
- },
- "tests": [
- {
- "description": "valid",
- "data": {"foo": 1, "bar": 2},
- "valid": true
- },
- {
- "description": "no dependency",
- "data": {"foo": "quux"},
- "valid": true
- },
- {
- "description": "wrong type",
- "data": {"foo": "quux", "bar": 2},
- "valid": false
- },
- {
- "description": "wrong type other",
- "data": {"foo": 2, "bar": "quux"},
- "valid": false
- },
- {
- "description": "wrong type both",
- "data": {"foo": "quux", "bar": "quux"},
- "valid": false
- }
- ]
- },
- {
- "description": "dependentSchemas with boolean subschemas",
- "schema": {
- "dependentSchemas": {
- "foo": true,
- "bar": false
- }
- },
- "tests": [
- {
- "description": "object with property having schema true is valid",
- "data": {"foo": 1},
- "valid": true
- },
- {
- "description": "object with property having schema false is invalid",
- "data": {"bar": 2},
- "valid": false
- },
- {
- "description": "object with both properties is invalid",
- "data": {"foo": 1, "bar": 2},
- "valid": false
- },
- {
- "description": "empty object is valid",
- "data": {},
- "valid": true
- }
- ]
- },
- {
- "description": "dependencies with escaped characters",
- "schema": {
- "dependentRequired": {
- "foo\nbar": ["foo\rbar"],
- "foo\"bar": ["foo'bar"]
- },
- "dependentSchemas": {
- "foo\tbar": {
- "minProperties": 4
- },
- "foo'bar": {"required": ["foo\"bar"]}
- }
- },
- "tests": [
- {
- "description": "valid object 1",
- "data": {
- "foo\nbar": 1,
- "foo\rbar": 2
- },
- "valid": true
- },
- {
- "description": "valid object 2",
- "data": {
- "foo\tbar": 1,
- "a": 2,
- "b": 3,
- "c": 4
- },
- "valid": true
- },
- {
- "description": "valid object 3",
- "data": {
- "foo'bar": 1,
- "foo\"bar": 2
- },
- "valid": true
- },
- {
- "description": "invalid object 1",
- "data": {
- "foo\nbar": 1,
- "foo": 2
- },
- "valid": false
- },
- {
- "description": "invalid object 2",
- "data": {
- "foo\tbar": 1,
- "a": 2
- },
- "valid": false
- },
- {
- "description": "invalid object 3",
- "data": {
- "foo'bar": 1
- },
- "valid": false
- },
- {
- "description": "invalid object 4",
- "data": {
- "foo\"bar": 2
- },
- "valid": false
- }
- ]
- }
-]
diff --git a/json/tests/draft2019-09/dependentRequired.json b/json/tests/draft2019-09/dependentRequired.json
new file mode 100644
index 0000000..c817120
--- /dev/null
+++ b/json/tests/draft2019-09/dependentRequired.json
@@ -0,0 +1,142 @@
+[
+ {
+ "description": "single dependency",
+ "schema": {"dependentRequired": {"bar": ["foo"]}},
+ "tests": [
+ {
+ "description": "neither",
+ "data": {},
+ "valid": true
+ },
+ {
+ "description": "nondependant",
+ "data": {"foo": 1},
+ "valid": true
+ },
+ {
+ "description": "with dependency",
+ "data": {"foo": 1, "bar": 2},
+ "valid": true
+ },
+ {
+ "description": "missing dependency",
+ "data": {"bar": 2},
+ "valid": false
+ },
+ {
+ "description": "ignores arrays",
+ "data": ["bar"],
+ "valid": true
+ },
+ {
+ "description": "ignores strings",
+ "data": "foobar",
+ "valid": true
+ },
+ {
+ "description": "ignores other non-objects",
+ "data": 12,
+ "valid": true
+ }
+ ]
+ },
+ {
+ "description": "empty dependents",
+ "schema": {"dependentRequired": {"bar": []}},
+ "tests": [
+ {
+ "description": "empty object",
+ "data": {},
+ "valid": true
+ },
+ {
+ "description": "object with one property",
+ "data": {"bar": 2},
+ "valid": true
+ },
+ {
+ "description": "non-object is valid",
+ "data": 1,
+ "valid": true
+ }
+ ]
+ },
+ {
+ "description": "multiple dependents required",
+ "schema": {"dependentRequired": {"quux": ["foo", "bar"]}},
+ "tests": [
+ {
+ "description": "neither",
+ "data": {},
+ "valid": true
+ },
+ {
+ "description": "nondependants",
+ "data": {"foo": 1, "bar": 2},
+ "valid": true
+ },
+ {
+ "description": "with dependencies",
+ "data": {"foo": 1, "bar": 2, "quux": 3},
+ "valid": true
+ },
+ {
+ "description": "missing dependency",
+ "data": {"foo": 1, "quux": 2},
+ "valid": false
+ },
+ {
+ "description": "missing other dependency",
+ "data": {"bar": 1, "quux": 2},
+ "valid": false
+ },
+ {
+ "description": "missing both dependencies",
+ "data": {"quux": 1},
+ "valid": false
+ }
+ ]
+ },
+ {
+ "description": "dependencies with escaped characters",
+ "schema": {
+ "dependentRequired": {
+ "foo\nbar": ["foo\rbar"],
+ "foo\"bar": ["foo'bar"]
+ }
+ },
+ "tests": [
+ {
+ "description": "CRLF",
+ "data": {
+ "foo\nbar": 1,
+ "foo\rbar": 2
+ },
+ "valid": true
+ },
+ {
+ "description": "quoted quotes",
+ "data": {
+ "foo'bar": 1,
+ "foo\"bar": 2
+ },
+ "valid": true
+ },
+ {
+ "description": "CRLF missing dependent",
+ "data": {
+ "foo\nbar": 1,
+ "foo": 2
+ },
+ "valid": false
+ },
+ {
+ "description": "quoted quotes missing dependent",
+ "data": {
+ "foo\"bar": 2
+ },
+ "valid": false
+ }
+ ]
+ }
+]
diff --git a/json/tests/draft2019-09/dependentSchemas.json b/json/tests/draft2019-09/dependentSchemas.json
new file mode 100644
index 0000000..e7921d1
--- /dev/null
+++ b/json/tests/draft2019-09/dependentSchemas.json
@@ -0,0 +1,114 @@
+[
+ {
+ "description": "single dependency",
+ "schema": {
+ "dependentSchemas": {
+ "bar": {
+ "properties": {
+ "foo": {"type": "integer"},
+ "bar": {"type": "integer"}
+ }
+ }
+ }
+ },
+ "tests": [
+ {
+ "description": "valid",
+ "data": {"foo": 1, "bar": 2},
+ "valid": true
+ },
+ {
+ "description": "no dependency",
+ "data": {"foo": "quux"},
+ "valid": true
+ },
+ {
+ "description": "wrong type",
+ "data": {"foo": "quux", "bar": 2},
+ "valid": false
+ },
+ {
+ "description": "wrong type other",
+ "data": {"foo": 2, "bar": "quux"},
+ "valid": false
+ },
+ {
+ "description": "wrong type both",
+ "data": {"foo": "quux", "bar": "quux"},
+ "valid": false
+ }
+ ]
+ },
+ {
+ "description": "boolean subschemas",
+ "schema": {
+ "dependentSchemas": {
+ "foo": true,
+ "bar": false
+ }
+ },
+ "tests": [
+ {
+ "description": "object with property having schema true is valid",
+ "data": {"foo": 1},
+ "valid": true
+ },
+ {
+ "description": "object with property having schema false is invalid",
+ "data": {"bar": 2},
+ "valid": false
+ },
+ {
+ "description": "object with both properties is invalid",
+ "data": {"foo": 1, "bar": 2},
+ "valid": false
+ },
+ {
+ "description": "empty object is valid",
+ "data": {},
+ "valid": true
+ }
+ ]
+ },
+ {
+ "description": "dependencies with escaped characters",
+ "schema": {
+ "dependentSchemas": {
+ "foo\tbar": {"minProperties": 4},
+ "foo'bar": {"required": ["foo\"bar"]}
+ }
+ },
+ "tests": [
+ {
+ "description": "quoted tab",
+ "data": {
+ "foo\tbar": 1,
+ "a": 2,
+ "b": 3,
+ "c": 4
+ },
+ "valid": true
+ },
+ {
+ "description": "quoted quote",
+ "data": {
+ "foo'bar": {"foo\"bar": 1}
+ },
+ "valid": false
+ },
+ {
+ "description": "quoted tab invalid under dependent schema",
+ "data": {
+ "foo\tbar": 1,
+ "a": 2
+ },
+ "valid": false
+ },
+ {
+ "description": "quoted quote invalid under dependent schema",
+ "data": {"foo'bar": 1},
+ "valid": false
+ }
+ ]
+ }
+]
diff --git a/json/tests/draft2019-09/ref.json b/json/tests/draft2019-09/ref.json
index 2fc7702..5b6ee16 100644
--- a/json/tests/draft2019-09/ref.json
+++ b/json/tests/draft2019-09/ref.json
@@ -75,13 +75,15 @@
{
"description": "escaped pointer ref",
"schema": {
- "tilda~field": {"type": "integer"},
- "slash/field": {"type": "integer"},
- "percent%field": {"type": "integer"},
+ "$defs": {
+ "tilda~field": {"type": "integer"},
+ "slash/field": {"type": "integer"},
+ "percent%field": {"type": "integer"}
+ },
"properties": {
- "tilda": {"$ref": "#/tilda~0field"},
- "slash": {"$ref": "#/slash~1field"},
- "percent": {"$ref": "#/percent%25field"}
+ "tilda": {"$ref": "#/$defs/tilda~0field"},
+ "slash": {"$ref": "#/$defs/slash~1field"},
+ "percent": {"$ref": "#/$defs/percent%25field"}
}
},
"tests": [
diff --git a/json/tests/draft2019-09/refRemote.json b/json/tests/draft2019-09/refRemote.json
index 9cadc92..515263d 100644
--- a/json/tests/draft2019-09/refRemote.json
+++ b/json/tests/draft2019-09/refRemote.json
@@ -17,7 +17,7 @@
},
{
"description": "fragment within remote ref",
- "schema": {"$ref": "http://localhost:1234/subSchemas.json#/integer"},
+ "schema": {"$ref": "http://localhost:1234/subSchemas-defs.json#/$defs/integer"},
"tests": [
{
"description": "remote fragment valid",
@@ -34,7 +34,7 @@
{
"description": "ref within remote ref",
"schema": {
- "$ref": "http://localhost:1234/subSchemas.json#/refToInteger"
+ "$ref": "http://localhost:1234/subSchemas-defs.json#/$defs/refToInteger"
},
"tests": [
{
@@ -76,7 +76,7 @@
"schema": {
"$id": "http://localhost:1234/scope_change_defs1.json",
"type" : "object",
- "properties": {"list": {"$ref": "#/$defs/baz"}},
+ "properties": {"list": {"$ref": "folder/"}},
"$defs": {
"baz": {
"$id": "folder/",
@@ -103,7 +103,7 @@
"schema": {
"$id": "http://localhost:1234/scope_change_defs2.json",
"type" : "object",
- "properties": {"list": {"$ref": "#/$defs/baz/$defs/bar"}},
+ "properties": {"list": {"$ref": "folder/#/$defs/bar"}},
"$defs": {
"baz": {
"$id": "folder/",
diff --git a/json/tests/draft2019-09/unevaluatedItems.json b/json/tests/draft2019-09/unevaluatedItems.json
new file mode 100644
index 0000000..54b686e
--- /dev/null
+++ b/json/tests/draft2019-09/unevaluatedItems.json
@@ -0,0 +1,87 @@
+[
+ {
+ "description": "anyOf with false unevaluatedItems",
+ "schema": {
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
+ "unevaluatedItems": false,
+ "anyOf": [
+ {"items": {"type": "string"}},
+ {"items": [true, true]}
+ ]
+ },
+ "tests": [
+ {
+ "description": "all strings is valid",
+ "data": ["foo", "bar", "baz"],
+ "valid": true
+ },
+ {
+ "description": "one item is valid",
+ "data": [1],
+ "valid": true
+ },
+ {
+ "description": "two items are valid",
+ "data": [1, "two"],
+ "valid": true
+ },
+ {
+ "description": "three items are invalid",
+ "data": [1, "two", "three"],
+ "valid": false
+ },
+ {
+ "description": "four strings are valid",
+ "data": ["one", "two", "three", "four"],
+ "valid": true
+ }
+ ]
+ },
+ {
+ "description": "complex unevaluated schema",
+ "schema": {
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
+ "unevaluatedItems": {
+ "allOf": [{"minLength": 3}, {"type": "string"}]
+ },
+ "if": {"items": [{"type": "integer"}, {"type": "array"}]}
+ },
+ "tests": [
+ {
+ "description": "empty array",
+ "data": [],
+ "valid": true
+ },
+ {
+ "description": "if passes with one item",
+ "data": [1],
+ "valid": true
+ },
+ {
+ "description": "if passes with two items",
+ "data": [1, [2, 3]],
+ "valid": true
+ },
+ {
+ "description": "if passes with third valid unevaluated item",
+ "data": [1, [2, 3], "long-string"],
+ "valid": true
+ },
+ {
+ "description": "if passes with third invalid unevaluated item",
+ "data": [1, [2, 3], "zz"],
+ "valid": false
+ },
+ {
+ "description": "if fails with all valid unevaluated items",
+ "data": ["all", "long", "strings"],
+ "valid": true
+ },
+ {
+ "description": "if and unevaluated items fail",
+ "data": ["a", "b", "c"],
+ "valid": false
+ }
+ ]
+ }
+]
diff --git a/json/tests/draft2019-09/unevaluatedProperties.json b/json/tests/draft2019-09/unevaluatedProperties.json
index f4096e1..2d999ce 100644
--- a/json/tests/draft2019-09/unevaluatedProperties.json
+++ b/json/tests/draft2019-09/unevaluatedProperties.json
@@ -1,21 +1,21 @@
[
{
- "description": "can peer inside allOf, results in no-op",
+ "description": "allOf with false unevaluatedProperties",
"schema": {
"$schema": "https://json-schema.org/draft/2019-09/schema",
"unevaluatedProperties": false,
"allOf": [
- {
- "properties": {
- "foo": { "type": ["string", "null"] },
- "bar": { "type": ["string", "null"] }
+ {
+ "properties": {
+ "foo": { "type": ["string", "null"] },
+ "bar": { "type": ["string", "null"] }
+ }
+ },
+ {
+ "additionalProperties": {
+ "not": { "enum": [ null ] }
+ }
}
- },
- {
- "additionalProperties": {
- "not": { "enum": [ null ] }
- }
- }
]
},
"tests": [
@@ -28,6 +28,64 @@
"description": "null prop is invalid",
"data": { "bar": "foo", "bob": null },
"valid": false
+ },
+ {
+ "description": "named property with wrong type is invalid",
+ "data": { "bar": "foo", "bob": "who?" },
+ "valid": true
+ }
+ ]
+ },
+ {
+ "description": "complex unevaluated schema",
+ "schema": {
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
+ "unevaluatedProperties": {
+ "allOf": [{"minLength": 3}, {"type": "string"}]
+ },
+ "if": {
+ "properties": {
+ "foo": {"type": "integer"},
+ "arr": {"type": "array"}
+ },
+ "required": ["foo"]
+ }
+ },
+ "tests": [
+ {
+ "description": "empty object",
+ "data": {},
+ "valid": true
+ },
+ {
+ "description": "if passes",
+ "data": {"foo": 3, "arr": [1,2]},
+ "valid": true
+ },
+ {
+ "description": "if passes with valid uneval",
+ "data": {"foo": 3, "arr": [1,2], "uneval": "long-string"},
+ "valid": true
+ },
+ {
+ "description": "if passes with invalid short uneval",
+ "data": {"foo": 3, "arr": [1,2], "uneval": "zz"},
+ "valid": false
+ },
+ {
+ "description": "if fails, and uneval fails because of array",
+ "data": {"foo": "not-an-int", "arr": [1,2], "uneval": "long-string"},
+ "valid": false
+ },
+ {
+ "description": "if fails with valid uneval",
+ "data": {"foo": "not-an-int", "uneval": "long-string"},
+ "valid": true
+ },
+ {
+ "description": "if fails with invalid uneval",
+ "data": {"foo": "zz", "uneval": "long-string"},
+ "valid": false
}
]
}