Skip to content

Commit

Permalink
schema tests update
Browse files Browse the repository at this point in the history
  • Loading branch information
redmitry committed Sep 2, 2024
1 parent 6510845 commit 2fc8bbf
Show file tree
Hide file tree
Showing 60 changed files with 3,600 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValidationError> errors) {

if (minLength != null && string.codePointCount(0, string.length()) < minLength) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions src/test/resources/json-schema-org/remotes/subSchemas-defs.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
]
25 changes: 0 additions & 25 deletions src/test/resources/json-schema-org/tests/draft2019-09/anchor.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
}
]
},
{
{
"description": "oneOf with missing optional property",
"schema": {
"$schema": "https://json-schema.org/draft/2019-09/schema",
Expand Down
Loading

0 comments on commit 2fc8bbf

Please sign in to comment.