From 49131a8713862727fea3f6a6149b98aeaac0c998 Mon Sep 17 00:00:00 2001 From: Patrick Boettcher
Date: Wed, 27 Nov 2019 13:48:54 +0100
Subject: [PATCH] fix #75: unknown keywords may contain sub-schemas
Now when an unknown keyword appears and its value is an object,
sub-unknown-keywords are inserted as possible sub-schemas.
---
src/json-validator.cpp | 9 +++++++--
test/issue-75/CMakeLists.txt | 3 +++
test/issue-75/TypeId.json | 10 ++++++++++
test/issue-75/instance.json | 1 +
test/issue-75/schema.json | 6 ++++++
5 files changed, 27 insertions(+), 2 deletions(-)
create mode 100644 test/issue-75/CMakeLists.txt
create mode 100644 test/issue-75/TypeId.json
create mode 100644 test/issue-75/instance.json
create mode 100644 test/issue-75/schema.json
diff --git a/src/json-validator.cpp b/src/json-validator.cpp
index c321dfa..680d63a 100644
--- a/src/json-validator.cpp
+++ b/src/json-validator.cpp
@@ -130,7 +130,7 @@ public:
{
auto &file = get_or_create_file(uri.location());
auto new_uri = uri.append(key);
- auto fragment = new_uri.fragment();
+ auto fragment = new_uri.pointer();
// is there a reference looking for this unknown-keyword, which is thus no longer a unknown keyword but a schema
auto unresolved = file.unresolved.find(fragment);
@@ -138,6 +138,11 @@ public:
schema::make(value, this, {}, {{new_uri}});
else // no, nothing ref'd it, keep for later
file.unknown_keywords[fragment] = value;
+
+ // recursively add possible subschemas of unknown keywords
+ if (value.type() == json::value_t::object)
+ for (auto &subsch : value.items())
+ insert_unknown_keyword(new_uri, subsch.key(), subsch.value());
}
std::shared_ptr