From 2cc7e9aaa501938efa6b648d0f3561c4657ee9ca Mon Sep 17 00:00:00 2001
From: Patrick Boettcher
Date: Thu, 2 Apr 2020 15:55:50 +0200
Subject: [PATCH] schema-URIs with plain name identifiers cannot have derived
sub-schema-URIs
fix #96
---
src/json-validator.cpp | 7 +++++++
test/issue-96/CMakeLists.txt | 6 ++++++
test/issue-96/instance.json | 1 +
test/issue-96/schema.json | 23 +++++++++++++++++++++++
4 files changed, 37 insertions(+)
create mode 100644 test/issue-96/CMakeLists.txt
create mode 100644 test/issue-96/instance.json
create mode 100644 test/issue-96/schema.json
diff --git a/src/json-validator.cpp b/src/json-validator.cpp
index 8a1e834..d4b6ad4 100644
--- a/src/json-validator.cpp
+++ b/src/json-validator.cpp
@@ -1118,6 +1118,13 @@ std::shared_ptr schema::make(json &schema,
const std::vector &keys,
std::vector uris)
{
+ // remove URIs which contain plain name identifiers, as sub-schemas cannot be referenced
+ for (auto uri = uris.begin(); uri != uris.end();)
+ if (uri->identifier() != "")
+ uri = uris.erase(uri);
+ else
+ uri++;
+
// append to all URIs the keys for this sub-schema
for (auto &key : keys)
for (auto &uri : uris)
diff --git a/test/issue-96/CMakeLists.txt b/test/issue-96/CMakeLists.txt
new file mode 100644
index 0000000..03582e6
--- /dev/null
+++ b/test/issue-96/CMakeLists.txt
@@ -0,0 +1,6 @@
+add_test_simple_schema(Issue::96
+ ${CMAKE_CURRENT_SOURCE_DIR}/schema.json
+ ${CMAKE_CURRENT_SOURCE_DIR}/instance.json)
+set_tests_properties(Issue::96
+ PROPERTIES
+ WILL_FAIL 1)
diff --git a/test/issue-96/instance.json b/test/issue-96/instance.json
new file mode 100644
index 0000000..0756430
--- /dev/null
+++ b/test/issue-96/instance.json
@@ -0,0 +1 @@
+{"top": {"value": 101}}
diff --git a/test/issue-96/schema.json b/test/issue-96/schema.json
new file mode 100644
index 0000000..c608adf
--- /dev/null
+++ b/test/issue-96/schema.json
@@ -0,0 +1,23 @@
+{
+ "$id": "http://xxx.local/schemas/mySchema.json",
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "definitions": {
+ "topDef": {
+ "$id": "#topDef_ref",
+ "type": "object",
+ "properties": {
+ "value": {
+ "type": "integer",
+ "maximum": 100
+ }
+ }
+ }
+ },
+
+ "type": "object",
+ "properties": {
+ "top": {
+ "$ref": "#/definitions/topDef"
+ }
+ }
+}