diff --git a/src/main/java/es/elixir/bsc/json/schema/impl/DefaultJsonSchemaParser.java b/src/main/java/es/elixir/bsc/json/schema/impl/DefaultJsonSchemaParser.java index c3fde04..4607750 100644 --- a/src/main/java/es/elixir/bsc/json/schema/impl/DefaultJsonSchemaParser.java +++ b/src/main/java/es/elixir/bsc/json/schema/impl/DefaultJsonSchemaParser.java @@ -110,26 +110,6 @@ public AbstractJsonSchema parse(JsonSchemaLocator locator, AbstractJsonSchemaEle } } - JsonValue $id = object.get(JsonSchema.ID); - if ($id == null) { - $id = object.get("id"); // draft4 - } - - if ($id != null) { - if ($id.getValueType() != JsonValue.ValueType.STRING) { - throw new JsonSchemaException(new ParsingError(ParsingMessage.INVALID_ATTRIBUTE_TYPE, - "id", $id.getValueType().name(), JsonValue.ValueType.STRING.name())); - } else { - final String id = ((JsonString)$id).getString(); - try { - locator = locator.resolve(URI.create(id)); - locator.setSchema(object); - } catch(IllegalArgumentException ex) { - throw new JsonSchemaException(new ParsingError(ParsingMessage.INVALID_REFERENCE, id)); - } - } - } - final JsonValue type_value = object.get(TYPE); final ValueType vtype; if (type_value == null) { @@ -152,6 +132,32 @@ public AbstractJsonSchema parse(JsonSchemaLocator locator, AbstractJsonSchemaEle "either a string or an array")); } } + + if (type == null) { + return new JsonMultitypeSchemaWrapper(parent, locator, jsonPointer, + vtype == ValueType.ARRAY ? type_value.asJsonArray() : null) + .read(this, object); + } + + JsonValue $id = object.get(JsonSchema.ID); + if ($id == null) { + $id = object.get("id"); // draft4 + } + + if ($id != null) { + if ($id.getValueType() != JsonValue.ValueType.STRING) { + throw new JsonSchemaException(new ParsingError(ParsingMessage.INVALID_ATTRIBUTE_TYPE, + "id", $id.getValueType().name(), JsonValue.ValueType.STRING.name())); + } else { + final String id = ((JsonString)$id).getString(); + try { + locator = locator.resolve(URI.create(id)); + locator.setSchema(object); + } catch(IllegalArgumentException ex) { + throw new JsonSchemaException(new ParsingError(ParsingMessage.INVALID_REFERENCE, id)); + } + } + } final JsonArray jenum = JsonSchemaUtil.check(object.get(ENUM), JsonValue.ValueType.ARRAY); if (jenum != null) { @@ -166,12 +172,6 @@ public AbstractJsonSchema parse(JsonSchemaLocator locator, AbstractJsonSchemaEle return new JsonConstImpl(parent, locator, jsonPointer).read(this, object); } - if (type == null) { - return new JsonMultitypeSchemaWrapper(parent, locator, jsonPointer, - vtype == ValueType.ARRAY ? type_value.asJsonArray() : null) - .read(this, object); - } - final AbstractJsonSchema schema; switch(type) { case OBJECT: schema = new JsonObjectSchemaImpl(parent, locator, jsonPointer); break; diff --git a/src/main/java/es/elixir/bsc/json/schema/model/impl/JsonMultitypeSchemaWrapper.java b/src/main/java/es/elixir/bsc/json/schema/model/impl/JsonMultitypeSchemaWrapper.java index 377d643..283d6d6 100644 --- a/src/main/java/es/elixir/bsc/json/schema/model/impl/JsonMultitypeSchemaWrapper.java +++ b/src/main/java/es/elixir/bsc/json/schema/model/impl/JsonMultitypeSchemaWrapper.java @@ -79,7 +79,7 @@ public JsonAnyOfImpl read(JsonSubschemaParser parser, JsonObject object) if (types == null) { for (JsonType val : JsonType.values()) { try { - final AbstractJsonSchema s = parser.parse(locator, this, getJsonPointer(), object, val); + final AbstractJsonSchema s = parser.parse(locator, this, jsonPointer, object, val); if (s != null) { add(s); } @@ -94,7 +94,7 @@ public JsonAnyOfImpl read(JsonSubschemaParser parser, JsonObject object) } try { final JsonType t = JsonType.fromValue(((JsonString)val).getString()); - add(parser.parse(locator, this, getJsonPointer(), object, t)); + add(parser.parse(locator, this, jsonPointer, object, t)); } catch(IllegalArgumentException ex) { throw new JsonSchemaException( new ParsingError(ParsingMessage.UNKNOWN_OBJECT_TYPE, val)); diff --git a/src/main/java/es/elixir/bsc/json/schema/model/impl/JsonStringSchemaImpl.java b/src/main/java/es/elixir/bsc/json/schema/model/impl/JsonStringSchemaImpl.java index 24a31a0..6a45803 100644 --- a/src/main/java/es/elixir/bsc/json/schema/model/impl/JsonStringSchemaImpl.java +++ b/src/main/java/es/elixir/bsc/json/schema/model/impl/JsonStringSchemaImpl.java @@ -151,7 +151,7 @@ public boolean validate(String jsonPointer, JsonValue value, JsonValue parent, return nerrors == errors.size(); } - + private void validate(String jsonPointer, String string, List errors) { if (minLength != null && string.codePointCount(0, string.length()) < minLength) { diff --git a/src/test/java/es/elixir/bsc/json/schema/org/tests/JsonSchemaIdTest.java b/src/test/java/es/elixir/bsc/json/schema/org/tests/JsonSchemaIdTest.java index b7342e8..9915db0 100644 --- a/src/test/java/es/elixir/bsc/json/schema/org/tests/JsonSchemaIdTest.java +++ b/src/test/java/es/elixir/bsc/json/schema/org/tests/JsonSchemaIdTest.java @@ -59,8 +59,8 @@ public void test_draft201909() { test(JSON_DRAFT201909_TEST_FILE); } -// @Test -// public void test_draft202012() { -// test(JSON_DRAFT202012_TEST_FILE); -// } + @Test + public void test_draft202012() { + test(JSON_DRAFT202012_TEST_FILE); + } } diff --git a/src/test/java/es/elixir/bsc/json/schema/org/tests/JsonSchemaRefRemoteTest.java b/src/test/java/es/elixir/bsc/json/schema/org/tests/JsonSchemaRefRemoteTest.java new file mode 100644 index 0000000..ea19e58 --- /dev/null +++ b/src/test/java/es/elixir/bsc/json/schema/org/tests/JsonSchemaRefRemoteTest.java @@ -0,0 +1,41 @@ +/** + * ***************************************************************************** + * Copyright (C) 2024 ELIXIR ES, Spanish National Bioinformatics Institute (INB) + * and Barcelona Supercomputing Center (BSC) + * + * Modifications to the initial code base are copyright of their respective + * authors, or their employers as appropriate. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + * ***************************************************************************** + */ + +package es.elixir.bsc.json.schema.org.tests; + +import org.junit.Test; + +/** + * @author Dmitry Repchevsky + */ +public class JsonSchemaRefRemoteTest extends JsonSchemaOrgTest { + + private final static String JSON_DRAFT4_TEST_FILE = "json-schema-org/tests/draft4/refRemote.json"; + +// @Test +// public void test_draft4() { +// test(JSON_DRAFT4_TEST_FILE); +// } +} diff --git a/src/test/java/es/elixir/bsc/json/schema/org/tests/JsonSchemaRefTest.java b/src/test/java/es/elixir/bsc/json/schema/org/tests/JsonSchemaRefTest.java index 84b91a8..deb1b1d 100644 --- a/src/test/java/es/elixir/bsc/json/schema/org/tests/JsonSchemaRefTest.java +++ b/src/test/java/es/elixir/bsc/json/schema/org/tests/JsonSchemaRefTest.java @@ -60,8 +60,8 @@ public void test_draft201909() { test(JSON_DRAFT201909_TEST_FILE, JsonSchemaVersion.SCHEMA_DRAFT_2019_09); } -// @Test -// public void test_draft202012() { -// test(JSON_DRAFT202012_TEST_FILE, JsonSchemaVersion.SCHEMA_DRAFT_2020_12); -// } + @Test + public void test_draft202012() { + test(JSON_DRAFT202012_TEST_FILE, JsonSchemaVersion.SCHEMA_DRAFT_2020_12); + } } diff --git a/src/test/java/es/elixir/bsc/json/schema/org/tests/JsonSchemaUnevaluatedItemsTest.java b/src/test/java/es/elixir/bsc/json/schema/org/tests/JsonSchemaUnevaluatedItemsTest.java index 81f79e2..41f63e9 100644 --- a/src/test/java/es/elixir/bsc/json/schema/org/tests/JsonSchemaUnevaluatedItemsTest.java +++ b/src/test/java/es/elixir/bsc/json/schema/org/tests/JsonSchemaUnevaluatedItemsTest.java @@ -41,8 +41,8 @@ public void test_draft201909() { test(JSON_DRAFT201909_TEST_FILE); } -// @Test -// public void test_draft202012() { -// test(JSON_DRAFT202012_TEST_FILE); -// } + @Test + public void test_draft202012() { + test(JSON_DRAFT202012_TEST_FILE); + } } diff --git a/src/test/java/es/elixir/bsc/json/schema/org/tests/JsonSchemaUniqueItemsTest.java b/src/test/java/es/elixir/bsc/json/schema/org/tests/JsonSchemaUniqueItemsTest.java index 5c682e3..3ff31e6 100644 --- a/src/test/java/es/elixir/bsc/json/schema/org/tests/JsonSchemaUniqueItemsTest.java +++ b/src/test/java/es/elixir/bsc/json/schema/org/tests/JsonSchemaUniqueItemsTest.java @@ -59,8 +59,8 @@ public void test_draft201909() { test(JSON_DRAFT201909_TEST_FILE); } -// @Test -// public void test_draft202012() { -// test(JSON_DRAFT202012_TEST_FILE); -// } + @Test + public void test_draft202012() { + test(JSON_DRAFT202012_TEST_FILE); + } } diff --git a/src/test/resources/json-schema-org/remotes/draft-next/subSchemas-defs.json b/src/test/resources/json-schema-org/remotes/draft-next/subSchemas-defs.json deleted file mode 100644 index 75b7583..0000000 --- a/src/test/resources/json-schema-org/remotes/draft-next/subSchemas-defs.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "$schema": "https://json-schema.org/draft/next/schema", - "$defs": { - "integer": { - "type": "integer" - }, - "refToInteger": { - "$ref": "#/$defs/integer" - } - } -} diff --git a/src/test/resources/json-schema-org/remotes/draft2019-09/subSchemas-defs.json b/src/test/resources/json-schema-org/remotes/draft2019-09/subSchemas-defs.json deleted file mode 100644 index fdfee68..0000000 --- a/src/test/resources/json-schema-org/remotes/draft2019-09/subSchemas-defs.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "integer": { - "type": "integer" - }, - "refToInteger": { - "$ref": "#/$defs/integer" - } - } -} diff --git a/src/test/resources/json-schema-org/remotes/draft2020-12/subSchemas-defs.json b/src/test/resources/json-schema-org/remotes/draft2020-12/subSchemas-defs.json deleted file mode 100644 index 1bb4846..0000000 --- a/src/test/resources/json-schema-org/remotes/draft2020-12/subSchemas-defs.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "integer": { - "type": "integer" - }, - "refToInteger": { - "$ref": "#/$defs/integer" - } - } -} diff --git a/src/test/resources/json-schema-org/remotes/subSchemas-defs.json b/src/test/resources/json-schema-org/remotes/subSchemas-defs.json deleted file mode 100644 index 50b7b6d..0000000 --- a/src/test/resources/json-schema-org/remotes/subSchemas-defs.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "$defs": { - "integer": { - "type": "integer" - }, - "refToInteger": { - "$ref": "#/$defs/integer" - } - } -} diff --git a/src/test/resources/json-schema-org/tests/draft2019-09/additionalProperties.json b/src/test/resources/json-schema-org/tests/draft2019-09/additionalProperties.json index f9f03bb..73f9b90 100644 --- a/src/test/resources/json-schema-org/tests/draft2019-09/additionalProperties.json +++ b/src/test/resources/json-schema-org/tests/draft2019-09/additionalProperties.json @@ -152,5 +152,62 @@ "valid": true } ] + }, + { + "description": "additionalProperties with propertyNames", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "propertyNames": { + "maxLength": 5 + }, + "additionalProperties": { + "type": "number" + } + }, + "tests": [ + { + "description": "Valid against both keywords", + "data": { "apple": 4 }, + "valid": true + }, + { + "description": "Valid against propertyNames, but not additionalProperties", + "data": { "fig": 2, "pear": "available" }, + "valid": false + } + ] + }, + { + "description": "dependentSchemas with additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": {"foo2": {}}, + "dependentSchemas": { + "foo" : {}, + "foo2": { + "properties": { + "bar":{} + } + } + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "additionalProperties doesn't consider dependentSchemas", + "data": {"foo": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see bar", + "data": {"bar": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see bar even when foo2 is present", + "data": { "foo2": "", "bar": ""}, + "valid": false + } + ] } ] diff --git a/src/test/resources/json-schema-org/tests/draft2019-09/anchor.json b/src/test/resources/json-schema-org/tests/draft2019-09/anchor.json index eb0a969..bce05e8 100644 --- a/src/test/resources/json-schema-org/tests/draft2019-09/anchor.json +++ b/src/test/resources/json-schema-org/tests/draft2019-09/anchor.json @@ -116,30 +116,5 @@ "valid": false } ] - }, - { - "description": "invalid anchors", - "comment": "Section 8.2.3", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "https://json-schema.org/draft/2019-09/schema" - }, - "tests": [ - { - "description": "MUST start with a letter (and not #)", - "data": { "$anchor" : "#foo" }, - "valid": false - }, - { - "description": "JSON pointers are not valid", - "data": { "$anchor" : "/a/b" }, - "valid": false - }, - { - "description": "invalid with valid beginning", - "data": { "$anchor" : "foo#something" }, - "valid": false - } - ] } ] diff --git a/src/test/resources/json-schema-org/tests/draft2019-09/maxLength.json b/src/test/resources/json-schema-org/tests/draft2019-09/maxLength.json index f242c3e..a0cc7d9 100644 --- a/src/test/resources/json-schema-org/tests/draft2019-09/maxLength.json +++ b/src/test/resources/json-schema-org/tests/draft2019-09/maxLength.json @@ -27,7 +27,7 @@ "valid": true }, { - "description": "two supplementary Unicode code points is long enough", + "description": "two graphemes is long enough", "data": "\uD83D\uDCA9\uD83D\uDCA9", "valid": true } diff --git a/src/test/resources/json-schema-org/tests/draft2019-09/oneOf.json b/src/test/resources/json-schema-org/tests/draft2019-09/oneOf.json index 9b7a220..c27d486 100644 --- a/src/test/resources/json-schema-org/tests/draft2019-09/oneOf.json +++ b/src/test/resources/json-schema-org/tests/draft2019-09/oneOf.json @@ -220,7 +220,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "$schema": "https://json-schema.org/draft/2019-09/schema", diff --git a/src/test/resources/json-schema-org/tests/draft2019-09/ref.json b/src/test/resources/json-schema-org/tests/draft2019-09/ref.json index ea56990..eff5305 100644 --- a/src/test/resources/json-schema-org/tests/draft2019-09/ref.json +++ b/src/test/resources/json-schema-org/tests/draft2019-09/ref.json @@ -791,21 +791,6 @@ } ] }, - { - "description": "URN base URI with f-component", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$comment": "RFC 8141 §2.3.3, but we don't allow fragments", - "$ref": "https://json-schema.org/draft/2019-09/schema" - }, - "tests": [ - { - "description": "is invalid", - "data": {"$id": "urn:example:foo-bar-baz-qux#somepart"}, - "valid": false - } - ] - }, { "description": "URN base URI with URN and JSON pointer ref", "schema": { @@ -1063,5 +1048,43 @@ "valid": false } ] - } + }, + { + "description": "$ref with $recursiveAnchor", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://example.com/schemas/unevaluated-items-are-disallowed", + "$ref": "/schemas/unevaluated-items-are-allowed", + "$recursiveAnchor": true, + "unevaluatedItems": false, + "$defs": { + "/schemas/unevaluated-items-are-allowed": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "/schemas/unevaluated-items-are-allowed", + "$recursiveAnchor": true, + "type": "array", + "items": [ + { + "type": "string" + }, + { + "$ref": "#" + } + ] + } + } + }, + "tests": [ + { + "description": "extra items allowed for inner arrays", + "data" : ["foo",["bar" , [] , 8]], + "valid": true + }, + { + "description": "extra items disallowed for root", + "data" : ["foo",["bar" , [] , 8], 8], + "valid": false + } + ] + } ] diff --git a/src/test/resources/json-schema-org/tests/draft2019-09/unevaluatedProperties.json b/src/test/resources/json-schema-org/tests/draft2019-09/unevaluatedProperties.json index a6cce8b..e876511 100644 --- a/src/test/resources/json-schema-org/tests/draft2019-09/unevaluatedProperties.json +++ b/src/test/resources/json-schema-org/tests/draft2019-09/unevaluatedProperties.json @@ -715,6 +715,102 @@ } ] }, + { + "description": "unevaluatedProperties before $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "unevaluatedProperties": false, + "properties": { + "foo": { "type": "string" } + }, + "$ref": "#/$defs/bar", + "$defs": { + "bar": { + "properties": { + "bar": { "type": "string" } + } + } + } + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with $recursiveRef", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://example.com/unevaluated-properties-with-recursive-ref/extended-tree", + + "$recursiveAnchor": true, + + "$ref": "./tree", + "properties": { + "name": { "type": "string" } + }, + + "$defs": { + "tree": { + "$id": "./tree", + "$recursiveAnchor": true, + + "type": "object", + "properties": { + "node": true, + "branches": { + "$comment": "unevaluatedProperties comes first so it's more likely to bugs errors with implementations that are sensitive to keyword ordering", + "unevaluatedProperties": false, + "$recursiveRef": "#" + } + }, + "required": ["node"] + } + } + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "name": "a", + "node": 1, + "branches": { + "name": "b", + "node": 2 + } + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "name": "a", + "node": 1, + "branches": { + "foo": "b", + "node": 2 + } + }, + "valid": false + } + ] + }, { "description": "unevaluatedProperties can't see inside cousins", "schema": { @@ -1471,5 +1567,38 @@ "valid": false } ] + }, + { + "description": "dependentSchemas with unevaluatedProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": {"foo2": {}}, + "dependentSchemas": { + "foo" : {}, + "foo2": { + "properties": { + "bar":{} + } + } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "unevaluatedProperties doesn't consider dependentSchemas", + "data": {"foo": ""}, + "valid": false + }, + { + "description": "unevaluatedProperties doesn't see bar when foo2 is absent", + "data": {"bar": ""}, + "valid": false + }, + { + "description": "unevaluatedProperties sees bar when foo2 is present", + "data": { "foo2": "", "bar": ""}, + "valid": true + } + ] } ] diff --git a/src/test/resources/json-schema-org/tests/draft2020-12/additionalProperties.json b/src/test/resources/json-schema-org/tests/draft2020-12/additionalProperties.json index 29e69c1..9618575 100644 --- a/src/test/resources/json-schema-org/tests/draft2020-12/additionalProperties.json +++ b/src/test/resources/json-schema-org/tests/draft2020-12/additionalProperties.json @@ -2,6 +2,7 @@ { "description": "additionalProperties being false does not allow other properties", + "specification": [ { "core":"10.3.2.3", "quote": "The value of \"additionalProperties\" MUST be a valid JSON Schema. Boolean \"false\" forbids everything." } ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "properties": {"foo": {}, "bar": {}}, @@ -43,6 +44,7 @@ }, { "description": "non-ASCII pattern with additionalProperties", + "specification": [ { "core":"10.3.2.3"} ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "patternProperties": {"^á": {}}, @@ -63,6 +65,7 @@ }, { "description": "additionalProperties with schema", + "specification": [ { "core":"10.3.2.3", "quote": "The value of \"additionalProperties\" MUST be a valid JSON Schema." } ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "properties": {"foo": {}, "bar": {}}, @@ -87,8 +90,8 @@ ] }, { - "description": - "additionalProperties can exist by itself", + "description": "additionalProperties can exist by itself", + "specification": [ { "core":"10.3.2.3", "quote": "With no other applicator applying to object instances. This validates all the instance values irrespective of their property names" } ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "additionalProperties": {"type": "boolean"} @@ -108,6 +111,7 @@ }, { "description": "additionalProperties are allowed by default", + "specification": [ { "core":"10.3.2.3", "quote": "Omitting this keyword has the same assertion behavior as an empty schema." } ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "properties": {"foo": {}, "bar": {}} @@ -122,6 +126,7 @@ }, { "description": "additionalProperties does not look in applicators", + "specification":[ { "core": "10.2", "quote": "Subschemas of applicator keywords evaluate the instance completely independently such that the results of one such subschema MUST NOT impact the results of sibling subschemas." } ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "allOf": [ @@ -139,6 +144,7 @@ }, { "description": "additionalProperties with null valued instance properties", + "specification": [ { "core":"10.3.2.3" } ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "additionalProperties": { @@ -152,5 +158,62 @@ "valid": true } ] + }, + { + "description": "additionalProperties with propertyNames", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "propertyNames": { + "maxLength": 5 + }, + "additionalProperties": { + "type": "number" + } + }, + "tests": [ + { + "description": "Valid against both keywords", + "data": { "apple": 4 }, + "valid": true + }, + { + "description": "Valid against propertyNames, but not additionalProperties", + "data": { "fig": 2, "pear": "available" }, + "valid": false + } + ] + }, + { + "description": "dependentSchemas with additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": {"foo2": {}}, + "dependentSchemas": { + "foo" : {}, + "foo2": { + "properties": { + "bar": {} + } + } + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "additionalProperties doesn't consider dependentSchemas", + "data": {"foo": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see bar", + "data": {"bar": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see bar even when foo2 is present", + "data": {"foo2": "", "bar": ""}, + "valid": false + } + ] } ] diff --git a/src/test/resources/json-schema-org/tests/draft2020-12/anchor.json b/src/test/resources/json-schema-org/tests/draft2020-12/anchor.json index 83a7166..99143fa 100644 --- a/src/test/resources/json-schema-org/tests/draft2020-12/anchor.json +++ b/src/test/resources/json-schema-org/tests/draft2020-12/anchor.json @@ -116,30 +116,5 @@ "valid": false } ] - }, - { - "description": "invalid anchors", - "comment": "Section 8.2.2", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://json-schema.org/draft/2020-12/schema" - }, - "tests": [ - { - "description": "MUST start with a letter (and not #)", - "data": { "$anchor" : "#foo" }, - "valid": false - }, - { - "description": "JSON pointers are not valid", - "data": { "$anchor" : "/a/b" }, - "valid": false - }, - { - "description": "invalid with valid beginning", - "data": { "$anchor" : "foo#something" }, - "valid": false - } - ] } ] diff --git a/src/test/resources/json-schema-org/tests/draft2020-12/dynamicRef.json b/src/test/resources/json-schema-org/tests/draft2020-12/dynamicRef.json index bff26ad..ffa211b 100644 --- a/src/test/resources/json-schema-org/tests/draft2020-12/dynamicRef.json +++ b/src/test/resources/json-schema-org/tests/draft2020-12/dynamicRef.json @@ -756,5 +756,60 @@ "valid": false } ] + }, + { + "description": "$dynamicRef skips over intermediate resources - direct reference", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/main", + "type": "object", + "properties": { + "bar-item": { + "$ref": "item" + } + }, + "$defs": { + "bar": { + "$id": "bar", + "type": "array", + "items": { + "$ref": "item" + }, + "$defs": { + "item": { + "$id": "item", + "type": "object", + "properties": { + "content": { + "$dynamicRef": "#content" + } + }, + "$defs": { + "defaultContent": { + "$dynamicAnchor": "content", + "type": "integer" + } + } + }, + "content": { + "$dynamicAnchor": "content", + "type": "string" + } + } + } + } + }, + "tests": [ + { + "description": "integer property passes", + "data": { "bar-item": { "content": 42 } }, + "valid": true + }, + { + "description": "string property fails", + "data": { "bar-item": { "content": "value" } }, + "valid": false + } + ] } ] diff --git a/src/test/resources/json-schema-org/tests/draft2020-12/oneOf.json b/src/test/resources/json-schema-org/tests/draft2020-12/oneOf.json index 416c8e5..7a7c7ff 100644 --- a/src/test/resources/json-schema-org/tests/draft2020-12/oneOf.json +++ b/src/test/resources/json-schema-org/tests/draft2020-12/oneOf.json @@ -220,7 +220,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", diff --git a/src/test/resources/json-schema-org/tests/draft2020-12/ref.json b/src/test/resources/json-schema-org/tests/draft2020-12/ref.json index 8d15fa4..a1d3efa 100644 --- a/src/test/resources/json-schema-org/tests/draft2020-12/ref.json +++ b/src/test/resources/json-schema-org/tests/draft2020-12/ref.json @@ -791,21 +791,6 @@ } ] }, - { - "description": "URN base URI with f-component", - "schema": { - "$comment": "RFC 8141 §2.3.3, but we don't allow fragments", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://json-schema.org/draft/2020-12/schema" - }, - "tests": [ - { - "description": "is invalid", - "data": {"$id": "urn:example:foo-bar-baz-qux#somepart"}, - "valid": false - } - ] - }, { "description": "URN base URI with URN and JSON pointer ref", "schema": { diff --git a/src/test/resources/json-schema-org/tests/draft2020-12/unevaluatedItems.json b/src/test/resources/json-schema-org/tests/draft2020-12/unevaluatedItems.json index ee0cb65..f861cef 100644 --- a/src/test/resources/json-schema-org/tests/draft2020-12/unevaluatedItems.json +++ b/src/test/resources/json-schema-org/tests/draft2020-12/unevaluatedItems.json @@ -793,7 +793,6 @@ "data": [ "b" ], "valid": false } - ] } ] diff --git a/src/test/resources/json-schema-org/tests/draft2020-12/unevaluatedProperties.json b/src/test/resources/json-schema-org/tests/draft2020-12/unevaluatedProperties.json index b8a2306..ae29c9e 100644 --- a/src/test/resources/json-schema-org/tests/draft2020-12/unevaluatedProperties.json +++ b/src/test/resources/json-schema-org/tests/draft2020-12/unevaluatedProperties.json @@ -1564,5 +1564,38 @@ "valid": false } ] + }, + { + "description": "dependentSchemas with unevaluatedProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": {"foo2": {}}, + "dependentSchemas": { + "foo" : {}, + "foo2": { + "properties": { + "bar":{} + } + } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "unevaluatedProperties doesn't consider dependentSchemas", + "data": {"foo": ""}, + "valid": false + }, + { + "description": "unevaluatedProperties doesn't see bar when foo2 is absent", + "data": {"bar": ""}, + "valid": false + }, + { + "description": "unevaluatedProperties sees bar when foo2 is present", + "data": { "foo2": "", "bar": ""}, + "valid": true + } + ] } ] diff --git a/src/test/resources/json-schema-org/tests/draft4/additionalItems.json b/src/test/resources/json-schema-org/tests/draft4/additionalItems.json index 9e094f2..c9e6815 100644 --- a/src/test/resources/json-schema-org/tests/draft4/additionalItems.json +++ b/src/test/resources/json-schema-org/tests/draft4/additionalItems.json @@ -1,4 +1,23 @@ [ + { + "description": "additionalItems as schema", + "schema": { + "items": [{}], + "additionalItems": {"type": "integer"} + }, + "tests": [ + { + "description": "additional items match schema", + "data": [ null, 2, 3, 4 ], + "valid": true + }, + { + "description": "additional items do not match schema", + "data": [ null, 2, 3, "foo" ], + "valid": false + } + ] + }, { "description": "when items is schema, additionalItems does nothing", "schema": { @@ -127,6 +146,25 @@ } ] }, + { + "description": "additionalItems with heterogeneous array", + "schema": { + "items": [{}], + "additionalItems": false + }, + "tests": [ + { + "description": "heterogeneous invalid instance", + "data": [ "foo", "bar", 37 ], + "valid": false + }, + { + "description": "valid instance", + "data": [ null ], + "valid": true + } + ] + }, { "description": "additionalItems with null instance elements", "schema": { diff --git a/src/test/resources/json-schema-org/tests/draft4/dependencies.json b/src/test/resources/json-schema-org/tests/draft4/dependencies.json index 51eeddf..9045ddc 100644 --- a/src/test/resources/json-schema-org/tests/draft4/dependencies.json +++ b/src/test/resources/json-schema-org/tests/draft4/dependencies.json @@ -190,5 +190,43 @@ "valid": false } ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "properties": { + "foo": {} + }, + "dependencies": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "matches root", + "data": {"foo": 1}, + "valid": false + }, + { + "description": "matches dependency", + "data": {"bar": 1}, + "valid": true + }, + { + "description": "matches both", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "no dependency", + "data": {"baz": 1}, + "valid": true + } + ] } ] diff --git a/src/test/resources/json-schema-org/tests/draft4/enum.json b/src/test/resources/json-schema-org/tests/draft4/enum.json index f085097..ce43acc 100644 --- a/src/test/resources/json-schema-org/tests/draft4/enum.json +++ b/src/test/resources/json-schema-org/tests/draft4/enum.json @@ -154,6 +154,27 @@ } ] }, + { + "description": "enum with [false] does not match [0]", + "schema": {"enum": [[false]]}, + "tests": [ + { + "description": "[false] is valid", + "data": [false], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [0], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [0.0], + "valid": false + } + ] + }, { "description": "enum with true does not match 1", "schema": {"enum": [true]}, @@ -175,6 +196,27 @@ } ] }, + { + "description": "enum with [true] does not match [1]", + "schema": {"enum": [[true]]}, + "tests": [ + { + "description": "[true] is valid", + "data": [true], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [1], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [1.0], + "valid": false + } + ] + }, { "description": "enum with 0 does not match false", "schema": {"enum": [0]}, @@ -196,6 +238,27 @@ } ] }, + { + "description": "enum with [0] does not match [false]", + "schema": {"enum": [[0]]}, + "tests": [ + { + "description": "[false] is invalid", + "data": [false], + "valid": false + }, + { + "description": "[0] is valid", + "data": [0], + "valid": true + }, + { + "description": "[0.0] is valid", + "data": [0.0], + "valid": true + } + ] + }, { "description": "enum with 1 does not match true", "schema": {"enum": [1]}, @@ -217,6 +280,27 @@ } ] }, + { + "description": "enum with [1] does not match [true]", + "schema": {"enum": [[1]]}, + "tests": [ + { + "description": "[true] is invalid", + "data": [true], + "valid": false + }, + { + "description": "[1] is valid", + "data": [1], + "valid": true + }, + { + "description": "[1.0] is valid", + "data": [1.0], + "valid": true + } + ] + }, { "description": "nul characters in strings", "schema": { "enum": [ "hello\u0000there" ] }, diff --git a/src/test/resources/json-schema-org/tests/draft4/items.json b/src/test/resources/json-schema-org/tests/draft4/items.json index 6483046..16ea070 100644 --- a/src/test/resources/json-schema-org/tests/draft4/items.json +++ b/src/test/resources/json-schema-org/tests/draft4/items.json @@ -1,4 +1,80 @@ [ + { + "description": "a schema given for items", + "schema": { + "items": {"type": "integer"} + }, + "tests": [ + { + "description": "valid items", + "data": [ 1, 2, 3 ], + "valid": true + }, + { + "description": "wrong type of items", + "data": [1, "x"], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": {"foo" : "bar"}, + "valid": true + }, + { + "description": "JavaScript pseudo-array is valid", + "data": { + "0": "invalid", + "length": 1 + }, + "valid": true + } + ] + }, + { + "description": "an array of schemas for items", + "schema": { + "items": [ + {"type": "integer"}, + {"type": "string"} + ] + }, + "tests": [ + { + "description": "correct types", + "data": [ 1, "foo" ], + "valid": true + }, + { + "description": "wrong types", + "data": [ "foo", 1 ], + "valid": false + }, + { + "description": "incomplete array of items", + "data": [ 1 ], + "valid": true + }, + { + "description": "array with additional items", + "data": [ 1, "foo", true ], + "valid": true + }, + { + "description": "empty array", + "data": [ ], + "valid": true + }, + { + "description": "JavaScript pseudo-array is valid", + "data": { + "0": "invalid", + "1": "valid", + "length": 2 + }, + "valid": true + } + ] + }, { "description": "items and subitems", "schema": { @@ -25,6 +101,43 @@ ] }, "tests": [ + { + "description": "valid items", + "data": [ + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ] + ], + "valid": true + }, + { + "description": "too many items", + "data": [ + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ] + ], + "valid": false + }, + { + "description": "too many sub-items", + "data": [ + [ {"foo": null}, {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ] + ], + "valid": false + }, + { + "description": "wrong item", + "data": [ + {"foo": null}, + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ] + ], + "valid": false + }, { "description": "wrong sub-item", "data": [ diff --git a/src/test/resources/json-schema-org/tests/draft4/maxLength.json b/src/test/resources/json-schema-org/tests/draft4/maxLength.json index 811d35b..3387959 100644 --- a/src/test/resources/json-schema-org/tests/draft4/maxLength.json +++ b/src/test/resources/json-schema-org/tests/draft4/maxLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "two supplementary Unicode code points is long enough", + "description": "two graphemes is long enough", "data": "\uD83D\uDCA9\uD83D\uDCA9", "valid": true } diff --git a/src/test/resources/json-schema-org/tests/draft4/minLength.json b/src/test/resources/json-schema-org/tests/draft4/minLength.json index 3f09158..6652c75 100644 --- a/src/test/resources/json-schema-org/tests/draft4/minLength.json +++ b/src/test/resources/json-schema-org/tests/draft4/minLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "one supplementary Unicode code point is not long enough", + "description": "one grapheme is not long enough", "data": "\uD83D\uDCA9", "valid": false } diff --git a/src/test/resources/json-schema-org/tests/draft4/minProperties.json b/src/test/resources/json-schema-org/tests/draft4/minProperties.json index e8a9090..49a0726 100644 --- a/src/test/resources/json-schema-org/tests/draft4/minProperties.json +++ b/src/test/resources/json-schema-org/tests/draft4/minProperties.json @@ -35,4 +35,4 @@ } ] } -] \ No newline at end of file +] diff --git a/src/test/resources/json-schema-org/tests/draft4/multipleOf.json b/src/test/resources/json-schema-org/tests/draft4/multipleOf.json index 9abeb97..ed2df4a 100644 --- a/src/test/resources/json-schema-org/tests/draft4/multipleOf.json +++ b/src/test/resources/json-schema-org/tests/draft4/multipleOf.json @@ -67,5 +67,16 @@ "valid": false } ] + }, + { + "description": "small multiple of large integer", + "schema": {"type": "integer", "multipleOf": 1e-8}, + "tests": [ + { + "description": "any integer is a multiple of 1e-8", + "data": 12391239123, + "valid": true + } + ] } ] diff --git a/src/test/resources/json-schema-org/tests/draft4/not.json b/src/test/resources/json-schema-org/tests/draft4/not.json index cbb7f46..525219c 100644 --- a/src/test/resources/json-schema-org/tests/draft4/not.json +++ b/src/test/resources/json-schema-org/tests/draft4/not.json @@ -91,6 +91,67 @@ "valid": true } ] + }, + { + "description": "forbid everything with empty schema", + "schema": { "not": {} }, + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + }, + { + "description": "object is invalid", + "data": {"foo": "bar"}, + "valid": false + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "array is invalid", + "data": ["foo"], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "double negation", + "schema": { "not": { "not": {} } }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] } - ] diff --git a/src/test/resources/json-schema-org/tests/draft4/oneOf.json b/src/test/resources/json-schema-org/tests/draft4/oneOf.json index fb63b08..2487f0e 100644 --- a/src/test/resources/json-schema-org/tests/draft4/oneOf.json +++ b/src/test/resources/json-schema-org/tests/draft4/oneOf.json @@ -159,7 +159,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "oneOf": [ diff --git a/src/test/resources/json-schema-org/tests/draft4/ref.json b/src/test/resources/json-schema-org/tests/draft4/ref.json index 1d3e167..b53bd2a 100644 --- a/src/test/resources/json-schema-org/tests/draft4/ref.json +++ b/src/test/resources/json-schema-org/tests/draft4/ref.json @@ -1,4 +1,392 @@ [ + { + "description": "root pointer ref", + "schema": { + "properties": { + "foo": {"$ref": "#"} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "match", + "data": {"foo": false}, + "valid": true + }, + { + "description": "recursive match", + "data": {"foo": {"foo": false}}, + "valid": true + }, + { + "description": "mismatch", + "data": {"bar": false}, + "valid": false + }, + { + "description": "recursive mismatch", + "data": {"foo": {"bar": false}}, + "valid": false + } + ] + }, + { + "description": "relative pointer ref to object", + "schema": { + "properties": { + "foo": {"type": "integer"}, + "bar": {"$ref": "#/properties/foo"} + } + }, + "tests": [ + { + "description": "match", + "data": {"bar": 3}, + "valid": true + }, + { + "description": "mismatch", + "data": {"bar": true}, + "valid": false + } + ] + }, + { + "description": "relative pointer ref to array", + "schema": { + "items": [ + {"type": "integer"}, + {"$ref": "#/items/0"} + ] + }, + "tests": [ + { + "description": "match array", + "data": [1, 2], + "valid": true + }, + { + "description": "mismatch array", + "data": [1, "foo"], + "valid": false + } + ] + }, + { + "description": "escaped pointer ref", + "schema": { + "definitions": { + "tilde~field": {"type": "integer"}, + "slash/field": {"type": "integer"}, + "percent%field": {"type": "integer"} + }, + "properties": { + "tilde": {"$ref": "#/definitions/tilde~0field"}, + "slash": {"$ref": "#/definitions/slash~1field"}, + "percent": {"$ref": "#/definitions/percent%25field"} + } + }, + "tests": [ + { + "description": "slash invalid", + "data": {"slash": "aoeu"}, + "valid": false + }, + { + "description": "tilde invalid", + "data": {"tilde": "aoeu"}, + "valid": false + }, + { + "description": "percent invalid", + "data": {"percent": "aoeu"}, + "valid": false + }, + { + "description": "slash valid", + "data": {"slash": 123}, + "valid": true + }, + { + "description": "tilde valid", + "data": {"tilde": 123}, + "valid": true + }, + { + "description": "percent valid", + "data": {"percent": 123}, + "valid": true + } + ] + }, + { + "description": "nested refs", + "schema": { + "definitions": { + "a": {"type": "integer"}, + "b": {"$ref": "#/definitions/a"}, + "c": {"$ref": "#/definitions/b"} + }, + "allOf": [{ "$ref": "#/definitions/c" }] + }, + "tests": [ + { + "description": "nested ref valid", + "data": 5, + "valid": true + }, + { + "description": "nested ref invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "ref overrides any sibling keywords", + "schema": { + "definitions": { + "reffed": { + "type": "array" + } + }, + "properties": { + "foo": { + "$ref": "#/definitions/reffed", + "maxItems": 2 + } + } + }, + "tests": [ + { + "description": "ref valid", + "data": { "foo": [] }, + "valid": true + }, + { + "description": "ref valid, maxItems ignored", + "data": { "foo": [ 1, 2, 3] }, + "valid": true + }, + { + "description": "ref invalid", + "data": { "foo": "string" }, + "valid": false + } + ] + }, + { + "description": "$ref prevents a sibling id from changing the base uri", + "schema": { + "id": "http://localhost:1234/sibling_id/base/", + "definitions": { + "foo": { + "id": "http://localhost:1234/sibling_id/foo.json", + "type": "string" + }, + "base_foo": { + "$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json", + "id": "foo.json", + "type": "number" + } + }, + "allOf": [ + { + "$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not http://localhost:1234/sibling_id/foo.json", + "id": "http://localhost:1234/sibling_id/", + "$ref": "foo.json" + } + ] + }, + "tests": [ + { + "description": "$ref resolves to /definitions/base_foo, data does not validate", + "data": "a", + "valid": false + }, + { + "description": "$ref resolves to /definitions/base_foo, data validates", + "data": 1, + "valid": true + } + ] + }, + { + "description": "remote ref, containing refs itself", + "schema": {"$ref": "http://json-schema.org/draft-04/schema#"}, + "tests": [ + { + "description": "remote ref valid", + "data": {"minLength": 1}, + "valid": true + }, + { + "description": "remote ref invalid", + "data": {"minLength": -1}, + "valid": false + } + ] + }, + { + "description": "property named $ref that is not a reference", + "schema": { + "properties": { + "$ref": {"type": "string"} + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": {"$ref": "a"}, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": {"$ref": 2}, + "valid": false + } + ] + }, + { + "description": "property named $ref, containing an actual $ref", + "schema": { + "properties": { + "$ref": {"$ref": "#/definitions/is-string"} + }, + "definitions": { + "is-string": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": {"$ref": "a"}, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": {"$ref": 2}, + "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 + } + ] + }, + { + "description": "refs with quote", + "schema": { + "properties": { + "foo\"bar": {"$ref": "#/definitions/foo%22bar"} + }, + "definitions": { + "foo\"bar": {"type": "number"} + } + }, + "tests": [ + { + "description": "object with numbers is valid", + "data": { + "foo\"bar": 1 + }, + "valid": true + }, + { + "description": "object with strings is invalid", + "data": { + "foo\"bar": "1" + }, + "valid": false + } + ] + }, { "description": "Location-independent identifier", "schema": { @@ -115,5 +503,90 @@ "valid": false } ] + }, + { + "description": "id with file URI still resolves pointers - *nix", + "schema": { + "id": "file:///folder/file.json", + "definitions": { + "foo": { + "type": "number" + } + }, + "allOf": [ + { + "$ref": "#/definitions/foo" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "id with file URI still resolves pointers - windows", + "schema": { + "id": "file:///c:/folder/file.json", + "definitions": { + "foo": { + "type": "number" + } + }, + "allOf": [ + { + "$ref": "#/definitions/foo" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "definitions": { + "": { + "definitions": { + "": { "type": "number" } + } + } + }, + "allOf": [ + { + "$ref": "#/definitions//definitions/" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] } ] diff --git a/src/test/resources/json-schema-org/tests/draft4/refRemote.json b/src/test/resources/json-schema-org/tests/draft4/refRemote.json new file mode 100644 index 0000000..64a618b --- /dev/null +++ b/src/test/resources/json-schema-org/tests/draft4/refRemote.json @@ -0,0 +1,189 @@ +[ + { + "description": "remote ref", + "schema": {"$ref": "http://localhost:1234/integer.json"}, + "tests": [ + { + "description": "remote ref valid", + "data": 1, + "valid": true + }, + { + "description": "remote ref invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "fragment within remote ref", + "schema": {"$ref": "http://localhost:1234/subSchemas.json#/definitions/integer"}, + "tests": [ + { + "description": "remote fragment valid", + "data": 1, + "valid": true + }, + { + "description": "remote fragment invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "ref within remote ref", + "schema": { + "$ref": "http://localhost:1234/subSchemas.json#/definitions/refToInteger" + }, + "tests": [ + { + "description": "ref within ref valid", + "data": 1, + "valid": true + }, + { + "description": "ref within ref invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "base URI change", + "schema": { + "id": "http://localhost:1234/", + "items": { + "id": "baseUriChange/", + "items": {"$ref": "folderInteger.json"} + } + }, + "tests": [ + { + "description": "base URI change ref valid", + "data": [[1]], + "valid": true + }, + { + "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": "baseUriChangeFolder/", + "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": "baseUriChangeFolderInSubschema/", + "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 + } + ] + }, + { + "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 + } + ] + }, + { + "description": "Location-independent identifier in remote ref", + "schema": { + "$ref": "http://localhost:1234/locationIndependentIdentifierDraft4.json#/definitions/refToInteger" + }, + "tests": [ + { + "description": "integer is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + } +] diff --git a/src/test/resources/json-schema-org/tests/draft4/uniqueItems.json b/src/test/resources/json-schema-org/tests/draft4/uniqueItems.json index 2ccf666..d2730c6 100644 --- a/src/test/resources/json-schema-org/tests/draft4/uniqueItems.json +++ b/src/test/resources/json-schema-org/tests/draft4/uniqueItems.json @@ -53,6 +53,11 @@ "data": [{"foo": "bar"}, {"foo": "bar"}], "valid": false }, + { + "description": "property order of array of objects is ignored", + "data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}], + "valid": false + }, { "description": "unique array of nested objects is valid", "data": [ diff --git a/src/test/resources/json-schema-org/tests/draft6/additionalItems.json b/src/test/resources/json-schema-org/tests/draft6/additionalItems.json index deb44fd..2c7d155 100644 --- a/src/test/resources/json-schema-org/tests/draft6/additionalItems.json +++ b/src/test/resources/json-schema-org/tests/draft6/additionalItems.json @@ -20,6 +20,29 @@ }, { "description": "when items is schema, additionalItems does nothing", + "schema": { + "items": { + "type": "integer" + }, + "additionalItems": { + "type": "string" + } + }, + "tests": [ + { + "description": "valid with a array of type integers", + "data": [1,2,3], + "valid": true + }, + { + "description": "invalid with a array of mixed types", + "data": [1,"2","3"], + "valid": false + } + ] + }, + { + "description": "when items is schema, boolean additionalItems does nothing", "schema": { "items": {}, "additionalItems": false @@ -146,6 +169,25 @@ } ] }, + { + "description": "additionalItems with heterogeneous array", + "schema": { + "items": [{}], + "additionalItems": false + }, + "tests": [ + { + "description": "heterogeneous invalid instance", + "data": [ "foo", "bar", 37 ], + "valid": false + }, + { + "description": "valid instance", + "data": [ null ], + "valid": true + } + ] + }, { "description": "additionalItems with null instance elements", "schema": { diff --git a/src/test/resources/json-schema-org/tests/draft6/dependencies.json b/src/test/resources/json-schema-org/tests/draft6/dependencies.json index a5e5428..c0bd809 100644 --- a/src/test/resources/json-schema-org/tests/draft6/dependencies.json +++ b/src/test/resources/json-schema-org/tests/draft6/dependencies.json @@ -244,5 +244,43 @@ "valid": false } ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "properties": { + "foo": {} + }, + "dependencies": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "matches root", + "data": {"foo": 1}, + "valid": false + }, + { + "description": "matches dependency", + "data": {"bar": 1}, + "valid": true + }, + { + "description": "matches both", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "no dependency", + "data": {"baz": 1}, + "valid": true + } + ] } ] diff --git a/src/test/resources/json-schema-org/tests/draft6/enum.json b/src/test/resources/json-schema-org/tests/draft6/enum.json index f085097..ce43acc 100644 --- a/src/test/resources/json-schema-org/tests/draft6/enum.json +++ b/src/test/resources/json-schema-org/tests/draft6/enum.json @@ -154,6 +154,27 @@ } ] }, + { + "description": "enum with [false] does not match [0]", + "schema": {"enum": [[false]]}, + "tests": [ + { + "description": "[false] is valid", + "data": [false], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [0], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [0.0], + "valid": false + } + ] + }, { "description": "enum with true does not match 1", "schema": {"enum": [true]}, @@ -175,6 +196,27 @@ } ] }, + { + "description": "enum with [true] does not match [1]", + "schema": {"enum": [[true]]}, + "tests": [ + { + "description": "[true] is valid", + "data": [true], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [1], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [1.0], + "valid": false + } + ] + }, { "description": "enum with 0 does not match false", "schema": {"enum": [0]}, @@ -196,6 +238,27 @@ } ] }, + { + "description": "enum with [0] does not match [false]", + "schema": {"enum": [[0]]}, + "tests": [ + { + "description": "[false] is invalid", + "data": [false], + "valid": false + }, + { + "description": "[0] is valid", + "data": [0], + "valid": true + }, + { + "description": "[0.0] is valid", + "data": [0.0], + "valid": true + } + ] + }, { "description": "enum with 1 does not match true", "schema": {"enum": [1]}, @@ -217,6 +280,27 @@ } ] }, + { + "description": "enum with [1] does not match [true]", + "schema": {"enum": [[1]]}, + "tests": [ + { + "description": "[true] is invalid", + "data": [true], + "valid": false + }, + { + "description": "[1] is valid", + "data": [1], + "valid": true + }, + { + "description": "[1.0] is valid", + "data": [1.0], + "valid": true + } + ] + }, { "description": "nul characters in strings", "schema": { "enum": [ "hello\u0000there" ] }, diff --git a/src/test/resources/json-schema-org/tests/draft6/maxLength.json b/src/test/resources/json-schema-org/tests/draft6/maxLength.json index 748b4da..be60c54 100644 --- a/src/test/resources/json-schema-org/tests/draft6/maxLength.json +++ b/src/test/resources/json-schema-org/tests/draft6/maxLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "two supplementary Unicode code points is long enough", + "description": "two graphemes is long enough", "data": "\uD83D\uDCA9\uD83D\uDCA9", "valid": true } diff --git a/src/test/resources/json-schema-org/tests/draft6/minLength.json b/src/test/resources/json-schema-org/tests/draft6/minLength.json index 64db948..23c68fe 100644 --- a/src/test/resources/json-schema-org/tests/draft6/minLength.json +++ b/src/test/resources/json-schema-org/tests/draft6/minLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "one supplementary Unicode code point is not long enough", + "description": "one grapheme is not long enough", "data": "\uD83D\uDCA9", "valid": false } diff --git a/src/test/resources/json-schema-org/tests/draft6/multipleOf.json b/src/test/resources/json-schema-org/tests/draft6/multipleOf.json index 25c25a9..e606979 100644 --- a/src/test/resources/json-schema-org/tests/draft6/multipleOf.json +++ b/src/test/resources/json-schema-org/tests/draft6/multipleOf.json @@ -67,5 +67,16 @@ "valid": false } ] + }, + { + "description": "small multiple of large integer", + "schema": {"type": "integer", "multipleOf": 1e-8}, + "tests": [ + { + "description": "any integer is a multiple of 1e-8", + "data": 12391239123, + "valid": true + } + ] } ] diff --git a/src/test/resources/json-schema-org/tests/draft6/not.json b/src/test/resources/json-schema-org/tests/draft6/not.json index fbfeb3b..b46c4ed 100644 --- a/src/test/resources/json-schema-org/tests/draft6/not.json +++ b/src/test/resources/json-schema-org/tests/draft6/not.json @@ -1,18 +1,253 @@ [ { - "description": "not with boolean schema true", - "schema": {"not": true}, + "description": "not", + "schema": { + "not": {"type": "integer"} + }, "tests": [ { - "description": "any value is invalid", + "description": "allowed", "data": "foo", + "valid": true + }, + { + "description": "disallowed", + "data": 1, + "valid": false + } + ] + }, + { + "description": "not multiple types", + "schema": { + "not": {"type": ["integer", "boolean"]} + }, + "tests": [ + { + "description": "valid", + "data": "foo", + "valid": true + }, + { + "description": "mismatch", + "data": 1, + "valid": false + }, + { + "description": "other mismatch", + "data": true, + "valid": false + } + ] + }, + { + "description": "not more complex schema", + "schema": { + "not": { + "type": "object", + "properties": { + "foo": { + "type": "string" + } + } + } + }, + "tests": [ + { + "description": "match", + "data": 1, + "valid": true + }, + { + "description": "other match", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "mismatch", + "data": {"foo": "bar"}, + "valid": false + } + ] + }, + { + "description": "forbidden property", + "schema": { + "properties": { + "foo": { + "not": {} + } + } + }, + "tests": [ + { + "description": "property present", + "data": {"foo": 1, "bar": 2}, "valid": false + }, + { + "description": "property absent", + "data": {"bar": 1, "baz": 2}, + "valid": true + } + ] + }, + { + "description": "forbid everything with empty schema", + "schema": { "not": {} }, + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + }, + { + "description": "object is invalid", + "data": {"foo": "bar"}, + "valid": false + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "array is invalid", + "data": ["foo"], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "forbid everything with boolean schema true", + "schema": { "not": true }, + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + }, + { + "description": "object is invalid", + "data": {"foo": "bar"}, + "valid": false + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "array is invalid", + "data": ["foo"], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "allow everything with boolean schema false", + "schema": { "not": false }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "boolean true is valid", + "data": true, + "valid": true + }, + { + "description": "boolean false is valid", + "data": false, + "valid": true + }, + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "object is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + }, + { + "description": "array is valid", + "data": ["foo"], + "valid": true + }, + { + "description": "empty array is valid", + "data": [], + "valid": true } ] }, { - "description": "not with boolean schema false", - "schema": {"not": false}, + "description": "double negation", + "schema": { "not": { "not": {} } }, "tests": [ { "description": "any value is valid", diff --git a/src/test/resources/json-schema-org/tests/draft6/oneOf.json b/src/test/resources/json-schema-org/tests/draft6/oneOf.json index eeb7ae8..c30a65c 100644 --- a/src/test/resources/json-schema-org/tests/draft6/oneOf.json +++ b/src/test/resources/json-schema-org/tests/draft6/oneOf.json @@ -203,7 +203,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "oneOf": [ diff --git a/src/test/resources/json-schema-org/tests/draft6/ref.json b/src/test/resources/json-schema-org/tests/draft6/ref.json index f58702f..379322c 100644 --- a/src/test/resources/json-schema-org/tests/draft6/ref.json +++ b/src/test/resources/json-schema-org/tests/draft6/ref.json @@ -1,4 +1,147 @@ [ + { + "description": "root pointer ref", + "schema": { + "properties": { + "foo": {"$ref": "#"} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "match", + "data": {"foo": false}, + "valid": true + }, + { + "description": "recursive match", + "data": {"foo": {"foo": false}}, + "valid": true + }, + { + "description": "mismatch", + "data": {"bar": false}, + "valid": false + }, + { + "description": "recursive mismatch", + "data": {"foo": {"bar": false}}, + "valid": false + } + ] + }, + { + "description": "relative pointer ref to object", + "schema": { + "properties": { + "foo": {"type": "integer"}, + "bar": {"$ref": "#/properties/foo"} + } + }, + "tests": [ + { + "description": "match", + "data": {"bar": 3}, + "valid": true + }, + { + "description": "mismatch", + "data": {"bar": true}, + "valid": false + } + ] + }, + { + "description": "relative pointer ref to array", + "schema": { + "items": [ + {"type": "integer"}, + {"$ref": "#/items/0"} + ] + }, + "tests": [ + { + "description": "match array", + "data": [1, 2], + "valid": true + }, + { + "description": "mismatch array", + "data": [1, "foo"], + "valid": false + } + ] + }, + { + "description": "escaped pointer ref", + "schema": { + "definitions": { + "tilde~field": {"type": "integer"}, + "slash/field": {"type": "integer"}, + "percent%field": {"type": "integer"} + }, + "properties": { + "tilde": {"$ref": "#/definitions/tilde~0field"}, + "slash": {"$ref": "#/definitions/slash~1field"}, + "percent": {"$ref": "#/definitions/percent%25field"} + } + }, + "tests": [ + { + "description": "slash invalid", + "data": {"slash": "aoeu"}, + "valid": false + }, + { + "description": "tilde invalid", + "data": {"tilde": "aoeu"}, + "valid": false + }, + { + "description": "percent invalid", + "data": {"percent": "aoeu"}, + "valid": false + }, + { + "description": "slash valid", + "data": {"slash": 123}, + "valid": true + }, + { + "description": "tilde valid", + "data": {"tilde": 123}, + "valid": true + }, + { + "description": "percent valid", + "data": {"percent": 123}, + "valid": true + } + ] + }, + { + "description": "nested refs", + "schema": { + "definitions": { + "a": {"type": "integer"}, + "b": {"$ref": "#/definitions/a"}, + "c": {"$ref": "#/definitions/b"} + }, + "allOf": [{ "$ref": "#/definitions/c" }] + }, + "tests": [ + { + "description": "nested ref valid", + "data": 5, + "valid": true + }, + { + "description": "nested ref invalid", + "data": "a", + "valid": false + } + ] + }, { "description": "ref overrides any sibling keywords", "schema": { @@ -31,5 +174,756 @@ "valid": false } ] - } + }, + { + "description": "$ref prevents a sibling $id from changing the base uri", + "schema": { + "$id": "http://localhost:1234/sibling_id/base/", + "definitions": { + "foo": { + "$id": "http://localhost:1234/sibling_id/foo.json", + "type": "string" + }, + "base_foo": { + "$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json", + "$id": "foo.json", + "type": "number" + } + }, + "allOf": [ + { + "$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not http://localhost:1234/sibling_id/foo.json", + "$id": "http://localhost:1234/sibling_id/", + "$ref": "foo.json" + } + ] + }, + "tests": [ + { + "description": "$ref resolves to /definitions/base_foo, data does not validate", + "data": "a", + "valid": false + }, + { + "description": "$ref resolves to /definitions/base_foo, data validates", + "data": 1, + "valid": true + } + ] + }, + { + "description": "remote ref, containing refs itself", + "schema": {"$ref": "http://json-schema.org/draft-06/schema#"}, + "tests": [ + { + "description": "remote ref valid", + "data": {"minLength": 1}, + "valid": true + }, + { + "description": "remote ref invalid", + "data": {"minLength": -1}, + "valid": false + } + ] + }, + { + "description": "property named $ref that is not a reference", + "schema": { + "properties": { + "$ref": {"type": "string"} + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": {"$ref": "a"}, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": {"$ref": 2}, + "valid": false + } + ] + }, + { + "description": "property named $ref, containing an actual $ref", + "schema": { + "properties": { + "$ref": {"$ref": "#/definitions/is-string"} + }, + "definitions": { + "is-string": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": {"$ref": "a"}, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": {"$ref": 2}, + "valid": false + } + ] + }, + { + "description": "$ref to boolean schema true", + "schema": { + "allOf": [{ "$ref": "#/definitions/bool" }], + "definitions": { + "bool": true + } + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "$ref to boolean schema false", + "schema": { + "allOf": [{ "$ref": "#/definitions/bool" }], + "definitions": { + "bool": false + } + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "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 + } + ] + }, + { + "description": "refs with quote", + "schema": { + "properties": { + "foo\"bar": {"$ref": "#/definitions/foo%22bar"} + }, + "definitions": { + "foo\"bar": {"type": "number"} + } + }, + "tests": [ + { + "description": "object with numbers is valid", + "data": { + "foo\"bar": 1 + }, + "valid": true + }, + { + "description": "object with strings is invalid", + "data": { + "foo\"bar": "1" + }, + "valid": false + } + ] + }, + { + "description": "Location-independent identifier", + "schema": { + "allOf": [{ + "$ref": "#foo" + }], + "definitions": { + "A": { + "$id": "#foo", + "type": "integer" + } + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] + }, + { + "description": "Reference an anchor with a non-relative URI", + "schema": { + "$id": "https://example.com/schema-with-anchor", + "allOf": [{ + "$ref": "https://example.com/schema-with-anchor#foo" + }], + "definitions": { + "A": { + "$id": "#foo", + "type": "integer" + } + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] + }, + { + "description": "Location-independent identifier with base URI change in subschema", + "schema": { + "$id": "http://localhost:1234/root", + "allOf": [{ + "$ref": "http://localhost:1234/nested.json#foo" + }], + "definitions": { + "A": { + "$id": "nested.json", + "definitions": { + "B": { + "$id": "#foo", + "type": "integer" + } + } + } + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] + }, + { + "description": "naive replacement of $ref with its destination is not correct", + "schema": { + "definitions": { + "a_string": { "type": "string" } + }, + "enum": [ + { "$ref": "#/definitions/a_string" } + ] + }, + "tests": [ + { + "description": "do not evaluate the $ref inside the enum, matching any string", + "data": "this is a string", + "valid": false + }, + { + "description": "do not evaluate the $ref inside the enum, definition exact match", + "data": { "type": "string" }, + "valid": false + }, + { + "description": "match the enum exactly", + "data": { "$ref": "#/definitions/a_string" }, + "valid": true + } + ] + }, + { + "description": "refs with relative uris and defs", + "schema": { + "$id": "http://example.com/schema-relative-uri-defs1.json", + "properties": { + "foo": { + "$id": "schema-relative-uri-defs2.json", + "definitions": { + "inner": { + "properties": { + "bar": { "type": "string" } + } + } + }, + "allOf": [ { "$ref": "#/definitions/inner" } ] + } + }, + "allOf": [ { "$ref": "schema-relative-uri-defs2.json" } ] + }, + "tests": [ + { + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true + } + ] + }, + { + "description": "relative refs with absolute uris and defs", + "schema": { + "$id": "http://example.com/schema-refs-absolute-uris-defs1.json", + "properties": { + "foo": { + "$id": "http://example.com/schema-refs-absolute-uris-defs2.json", + "definitions": { + "inner": { + "properties": { + "bar": { "type": "string" } + } + } + }, + "allOf": [ { "$ref": "#/definitions/inner" } ] + } + }, + "allOf": [ { "$ref": "schema-refs-absolute-uris-defs2.json" } ] + }, + "tests": [ + { + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true + } + ] + }, + { + "description": "simple URN base URI with $ref via the URN", + "schema": { + "$comment": "URIs do not have to have HTTP(s) schemes", + "$id": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed", + "minimum": 30, + "properties": { + "foo": {"$ref": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed"} + } + }, + "tests": [ + { + "description": "valid under the URN IDed schema", + "data": {"foo": 37}, + "valid": true + }, + { + "description": "invalid under the URN IDed schema", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "simple URN base URI with JSON pointer", + "schema": { + "$comment": "URIs do not have to have HTTP(s) schemes", + "$id": "urn:uuid:deadbeef-1234-00ff-ff00-4321feebdaed", + "properties": { + "foo": {"$ref": "#/definitions/bar"} + }, + "definitions": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with NSS", + "schema": { + "$comment": "RFC 8141 §2.2", + "$id": "urn:example:1/406/47452/2", + "properties": { + "foo": {"$ref": "#/definitions/bar"} + }, + "definitions": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with r-component", + "schema": { + "$comment": "RFC 8141 §2.3.1", + "$id": "urn:example:foo-bar-baz-qux?+CCResolve:cc=uk", + "properties": { + "foo": {"$ref": "#/definitions/bar"} + }, + "definitions": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with q-component", + "schema": { + "$comment": "RFC 8141 §2.3.2", + "$id": "urn:example:weather?=op=map&lat=39.56&lon=-104.85&datetime=1969-07-21T02:56:15Z", + "properties": { + "foo": {"$ref": "#/definitions/bar"} + }, + "definitions": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with URN and JSON pointer ref", + "schema": { + "$id": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed", + "properties": { + "foo": {"$ref": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed#/definitions/bar"} + }, + "definitions": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with URN and anchor ref", + "schema": { + "$id": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed", + "properties": { + "foo": {"$ref": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed#something"} + }, + "definitions": { + "bar": { + "$id": "#something", + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "ref with absolute-path-reference", + "schema": { + "$id": "http://example.com/ref/absref.json", + "definitions": { + "a": { + "$id": "http://example.com/ref/absref/foobar.json", + "type": "number" + }, + "b": { + "$id": "http://example.com/absref/foobar.json", + "type": "string" + } + }, + "allOf": [ + { "$ref": "/absref/foobar.json" } + ] + }, + "tests": [ + { + "description": "a string is valid", + "data": "foo", + "valid": true + }, + { + "description": "an integer is invalid", + "data": 12, + "valid": false + } + ] + }, + { + "description": "$id with file URI still resolves pointers - *nix", + "schema": { + "$id": "file:///folder/file.json", + "definitions": { + "foo": { + "type": "number" + } + }, + "allOf": [ + { + "$ref": "#/definitions/foo" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "$id with file URI still resolves pointers - windows", + "schema": { + "$id": "file:///c:/folder/file.json", + "definitions": { + "foo": { + "type": "number" + } + }, + "allOf": [ + { + "$ref": "#/definitions/foo" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "definitions": { + "": { + "definitions": { + "": { "type": "number" } + } + } + }, + "allOf": [ + { + "$ref": "#/definitions//definitions/" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + } ] diff --git a/src/test/resources/json-schema-org/tests/draft6/refRemote.json b/src/test/resources/json-schema-org/tests/draft6/refRemote.json index cdaadfd..28459c4 100644 --- a/src/test/resources/json-schema-org/tests/draft6/refRemote.json +++ b/src/test/resources/json-schema-org/tests/draft6/refRemote.json @@ -1,4 +1,105 @@ [ + { + "description": "remote ref", + "schema": {"$ref": "http://localhost:1234/integer.json"}, + "tests": [ + { + "description": "remote ref valid", + "data": 1, + "valid": true + }, + { + "description": "remote ref invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "fragment within remote ref", + "schema": {"$ref": "http://localhost:1234/subSchemas.json#/definitions/integer"}, + "tests": [ + { + "description": "remote fragment valid", + "data": 1, + "valid": true + }, + { + "description": "remote fragment invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "ref within remote ref", + "schema": { + "$ref": "http://localhost:1234/subSchemas.json#/definitions/refToInteger" + }, + "tests": [ + { + "description": "ref within ref valid", + "data": 1, + "valid": true + }, + { + "description": "ref within ref invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "base URI change", + "schema": { + "$id": "http://localhost:1234/", + "items": { + "$id": "baseUriChange/", + "items": {"$ref": "folderInteger.json"} + } + }, + "tests": [ + { + "description": "base URI change ref valid", + "data": [[1]], + "valid": true + }, + { + "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": "baseUriChangeFolder/", + "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": { @@ -24,6 +125,132 @@ "description": "number is valid", "data": {"list": [1]}, "valid": true + }, + { + "description": "string is invalid", + "data": {"list": ["a"]}, + "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 + } + ] + }, + { + "description": "remote ref with ref to definitions", + "schema": { + "$id": "http://localhost:1234/schema-remote-ref-ref-defs1.json", + "allOf": [ + { "$ref": "ref-and-definitions.json" } + ] + }, + "tests": [ + { + "description": "invalid", + "data": { + "bar": 1 + }, + "valid": false + }, + { + "description": "valid", + "data": { + "bar": "a" + }, + "valid": true + } + ] + }, + { + "description": "Location-independent identifier in remote ref", + "schema": { + "$ref": "http://localhost:1234/locationIndependentIdentifierPre2019.json#/definitions/refToInteger" + }, + "tests": [ + { + "description": "integer is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "retrieved nested refs resolve relative to their URI not $id", + "schema": { + "$id": "http://localhost:1234/some-id", + "properties": { + "name": {"$ref": "nested/foo-ref-string.json"} + } + }, + "tests": [ + { + "description": "number is invalid", + "data": { + "name": {"foo": 1} + }, + "valid": false + }, + { + "description": "string is valid", + "data": { + "name": {"foo": "a"} + }, + "valid": true + } + ] + }, + { + "description": "$ref to $ref finds location-independent $id", + "schema": { + "$ref": "http://localhost:1234/draft6/detached-ref.json#/definitions/foo" + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false } ] } diff --git a/src/test/resources/json-schema-org/tests/draft6/uniqueItems.json b/src/test/resources/json-schema-org/tests/draft6/uniqueItems.json index 2ccf666..d2730c6 100644 --- a/src/test/resources/json-schema-org/tests/draft6/uniqueItems.json +++ b/src/test/resources/json-schema-org/tests/draft6/uniqueItems.json @@ -53,6 +53,11 @@ "data": [{"foo": "bar"}, {"foo": "bar"}], "valid": false }, + { + "description": "property order of array of objects is ignored", + "data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}], + "valid": false + }, { "description": "unique array of nested objects is valid", "data": [ diff --git a/src/test/resources/json-schema-org/tests/draft7/additionalItems.json b/src/test/resources/json-schema-org/tests/draft7/additionalItems.json index deb44fd..2c7d155 100644 --- a/src/test/resources/json-schema-org/tests/draft7/additionalItems.json +++ b/src/test/resources/json-schema-org/tests/draft7/additionalItems.json @@ -20,6 +20,29 @@ }, { "description": "when items is schema, additionalItems does nothing", + "schema": { + "items": { + "type": "integer" + }, + "additionalItems": { + "type": "string" + } + }, + "tests": [ + { + "description": "valid with a array of type integers", + "data": [1,2,3], + "valid": true + }, + { + "description": "invalid with a array of mixed types", + "data": [1,"2","3"], + "valid": false + } + ] + }, + { + "description": "when items is schema, boolean additionalItems does nothing", "schema": { "items": {}, "additionalItems": false @@ -146,6 +169,25 @@ } ] }, + { + "description": "additionalItems with heterogeneous array", + "schema": { + "items": [{}], + "additionalItems": false + }, + "tests": [ + { + "description": "heterogeneous invalid instance", + "data": [ "foo", "bar", 37 ], + "valid": false + }, + { + "description": "valid instance", + "data": [ null ], + "valid": true + } + ] + }, { "description": "additionalItems with null instance elements", "schema": { diff --git a/src/test/resources/json-schema-org/tests/draft7/dependencies.json b/src/test/resources/json-schema-org/tests/draft7/dependencies.json index a5e5428..c0bd809 100644 --- a/src/test/resources/json-schema-org/tests/draft7/dependencies.json +++ b/src/test/resources/json-schema-org/tests/draft7/dependencies.json @@ -244,5 +244,43 @@ "valid": false } ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "properties": { + "foo": {} + }, + "dependencies": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "matches root", + "data": {"foo": 1}, + "valid": false + }, + { + "description": "matches dependency", + "data": {"bar": 1}, + "valid": true + }, + { + "description": "matches both", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "no dependency", + "data": {"baz": 1}, + "valid": true + } + ] } ] diff --git a/src/test/resources/json-schema-org/tests/draft7/enum.json b/src/test/resources/json-schema-org/tests/draft7/enum.json index f085097..ce43acc 100644 --- a/src/test/resources/json-schema-org/tests/draft7/enum.json +++ b/src/test/resources/json-schema-org/tests/draft7/enum.json @@ -154,6 +154,27 @@ } ] }, + { + "description": "enum with [false] does not match [0]", + "schema": {"enum": [[false]]}, + "tests": [ + { + "description": "[false] is valid", + "data": [false], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [0], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [0.0], + "valid": false + } + ] + }, { "description": "enum with true does not match 1", "schema": {"enum": [true]}, @@ -175,6 +196,27 @@ } ] }, + { + "description": "enum with [true] does not match [1]", + "schema": {"enum": [[true]]}, + "tests": [ + { + "description": "[true] is valid", + "data": [true], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [1], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [1.0], + "valid": false + } + ] + }, { "description": "enum with 0 does not match false", "schema": {"enum": [0]}, @@ -196,6 +238,27 @@ } ] }, + { + "description": "enum with [0] does not match [false]", + "schema": {"enum": [[0]]}, + "tests": [ + { + "description": "[false] is invalid", + "data": [false], + "valid": false + }, + { + "description": "[0] is valid", + "data": [0], + "valid": true + }, + { + "description": "[0.0] is valid", + "data": [0.0], + "valid": true + } + ] + }, { "description": "enum with 1 does not match true", "schema": {"enum": [1]}, @@ -217,6 +280,27 @@ } ] }, + { + "description": "enum with [1] does not match [true]", + "schema": {"enum": [[1]]}, + "tests": [ + { + "description": "[true] is invalid", + "data": [true], + "valid": false + }, + { + "description": "[1] is valid", + "data": [1], + "valid": true + }, + { + "description": "[1.0] is valid", + "data": [1.0], + "valid": true + } + ] + }, { "description": "nul characters in strings", "schema": { "enum": [ "hello\u0000there" ] }, diff --git a/src/test/resources/json-schema-org/tests/draft7/maxLength.json b/src/test/resources/json-schema-org/tests/draft7/maxLength.json index 748b4da..be60c54 100644 --- a/src/test/resources/json-schema-org/tests/draft7/maxLength.json +++ b/src/test/resources/json-schema-org/tests/draft7/maxLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "two supplementary Unicode code points is long enough", + "description": "two graphemes is long enough", "data": "\uD83D\uDCA9\uD83D\uDCA9", "valid": true } diff --git a/src/test/resources/json-schema-org/tests/draft7/minLength.json b/src/test/resources/json-schema-org/tests/draft7/minLength.json index 64db948..23c68fe 100644 --- a/src/test/resources/json-schema-org/tests/draft7/minLength.json +++ b/src/test/resources/json-schema-org/tests/draft7/minLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "one supplementary Unicode code point is not long enough", + "description": "one grapheme is not long enough", "data": "\uD83D\uDCA9", "valid": false } diff --git a/src/test/resources/json-schema-org/tests/draft7/multipleOf.json b/src/test/resources/json-schema-org/tests/draft7/multipleOf.json index 25c25a9..e606979 100644 --- a/src/test/resources/json-schema-org/tests/draft7/multipleOf.json +++ b/src/test/resources/json-schema-org/tests/draft7/multipleOf.json @@ -67,5 +67,16 @@ "valid": false } ] + }, + { + "description": "small multiple of large integer", + "schema": {"type": "integer", "multipleOf": 1e-8}, + "tests": [ + { + "description": "any integer is a multiple of 1e-8", + "data": 12391239123, + "valid": true + } + ] } ] diff --git a/src/test/resources/json-schema-org/tests/draft7/not.json b/src/test/resources/json-schema-org/tests/draft7/not.json index 98de0ed..b46c4ed 100644 --- a/src/test/resources/json-schema-org/tests/draft7/not.json +++ b/src/test/resources/json-schema-org/tests/draft7/not.json @@ -93,19 +93,161 @@ ] }, { - "description": "not with boolean schema true", - "schema": {"not": true}, + "description": "forbid everything with empty schema", + "schema": { "not": {} }, "tests": [ { - "description": "any value is invalid", + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is invalid", "data": "foo", "valid": false + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + }, + { + "description": "object is invalid", + "data": {"foo": "bar"}, + "valid": false + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "array is invalid", + "data": ["foo"], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "forbid everything with boolean schema true", + "schema": { "not": true }, + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + }, + { + "description": "object is invalid", + "data": {"foo": "bar"}, + "valid": false + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "array is invalid", + "data": ["foo"], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "allow everything with boolean schema false", + "schema": { "not": false }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "boolean true is valid", + "data": true, + "valid": true + }, + { + "description": "boolean false is valid", + "data": false, + "valid": true + }, + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "object is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + }, + { + "description": "array is valid", + "data": ["foo"], + "valid": true + }, + { + "description": "empty array is valid", + "data": [], + "valid": true } ] }, { - "description": "not with boolean schema false", - "schema": {"not": false}, + "description": "double negation", + "schema": { "not": { "not": {} } }, "tests": [ { "description": "any value is valid", diff --git a/src/test/resources/json-schema-org/tests/draft7/oneOf.json b/src/test/resources/json-schema-org/tests/draft7/oneOf.json index eeb7ae8..c30a65c 100644 --- a/src/test/resources/json-schema-org/tests/draft7/oneOf.json +++ b/src/test/resources/json-schema-org/tests/draft7/oneOf.json @@ -203,7 +203,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "oneOf": [ diff --git a/src/test/resources/json-schema-org/tests/draft7/ref.json b/src/test/resources/json-schema-org/tests/draft7/ref.json index ab67f0e..82e1e16 100644 --- a/src/test/resources/json-schema-org/tests/draft7/ref.json +++ b/src/test/resources/json-schema-org/tests/draft7/ref.json @@ -445,6 +445,33 @@ } ] }, + { + "description": "Reference an anchor with a non-relative URI", + "schema": { + "$id": "https://example.com/schema-with-anchor", + "allOf": [{ + "$ref": "https://example.com/schema-with-anchor#foo" + }], + "definitions": { + "A": { + "$id": "#foo", + "type": "integer" + } + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] + }, { "description": "Location-independent identifier with base URI change in subschema", "schema": { @@ -818,5 +845,199 @@ "valid": false } ] + }, + { + "description": "ref to if", + "schema": { + "allOf": [ + {"$ref": "http://example.com/ref/if"}, + { + "if": { + "$id": "http://example.com/ref/if", + "type": "integer" + } + } + ] + }, + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true + } + ] + }, + { + "description": "ref to then", + "schema": { + "allOf": [ + {"$ref": "http://example.com/ref/then"}, + { + "then": { + "$id": "http://example.com/ref/then", + "type": "integer" + } + } + ] + }, + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true + } + ] + }, + { + "description": "ref to else", + "schema": { + "allOf": [ + {"$ref": "http://example.com/ref/else"}, + { + "else": { + "$id": "http://example.com/ref/else", + "type": "integer" + } + } + ] + }, + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true + } + ] + }, + { + "description": "ref with absolute-path-reference", + "schema": { + "$id": "http://example.com/ref/absref.json", + "definitions": { + "a": { + "$id": "http://example.com/ref/absref/foobar.json", + "type": "number" + }, + "b": { + "$id": "http://example.com/absref/foobar.json", + "type": "string" + } + }, + "allOf": [ + { "$ref": "/absref/foobar.json" } + ] + }, + "tests": [ + { + "description": "a string is valid", + "data": "foo", + "valid": true + }, + { + "description": "an integer is invalid", + "data": 12, + "valid": false + } + ] + }, + { + "description": "$id with file URI still resolves pointers - *nix", + "schema": { + "$id": "file:///folder/file.json", + "definitions": { + "foo": { + "type": "number" + } + }, + "allOf": [ + { + "$ref": "#/definitions/foo" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "$id with file URI still resolves pointers - windows", + "schema": { + "$id": "file:///c:/folder/file.json", + "definitions": { + "foo": { + "type": "number" + } + }, + "allOf": [ + { + "$ref": "#/definitions/foo" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "definitions": { + "": { + "definitions": { + "": { "type": "number" } + } + } + }, + "allOf": [ + { + "$ref": "#/definitions//definitions/" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] } ] diff --git a/src/test/resources/json-schema-org/tests/draft7/refRemote.json b/src/test/resources/json-schema-org/tests/draft7/refRemote.json index c2b2002..22185d6 100644 --- a/src/test/resources/json-schema-org/tests/draft7/refRemote.json +++ b/src/test/resources/json-schema-org/tests/draft7/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.json#/definitions/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.json#/definitions/refToInteger" }, "tests": [ { @@ -235,5 +235,23 @@ "valid": true } ] + }, + { + "description": "$ref to $ref finds location-independent $id", + "schema": { + "$ref": "http://localhost:1234/draft7/detached-ref.json#/definitions/foo" + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] } ] diff --git a/src/test/resources/json-schema-org/tests/draft7/uniqueItems.json b/src/test/resources/json-schema-org/tests/draft7/uniqueItems.json index 2ccf666..d2730c6 100644 --- a/src/test/resources/json-schema-org/tests/draft7/uniqueItems.json +++ b/src/test/resources/json-schema-org/tests/draft7/uniqueItems.json @@ -53,6 +53,11 @@ "data": [{"foo": "bar"}, {"foo": "bar"}], "valid": false }, + { + "description": "property order of array of objects is ignored", + "data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}], + "valid": false + }, { "description": "unique array of nested objects is valid", "data": [