From 5617eeec4e0c2cd8733f8ebb77a0efdeab0d16e3 Mon Sep 17 00:00:00 2001 From: Patrick Boettcher
Date: Mon, 14 Oct 2019 11:43:22 +0200
Subject: [PATCH] root-schema: allow re-setting a new root-schema
Fixes #70
---
src/json-schema.hpp | 2 +-
src/json-validator.cpp | 3 ++-
test/CMakeLists.txt | 6 +++++-
test/issue-70.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 52 insertions(+), 3 deletions(-)
create mode 100644 test/issue-70.cpp
diff --git a/src/json-schema.hpp b/src/json-schema.hpp
index 165a9c9..df088da 100644
--- a/src/json-schema.hpp
+++ b/src/json-schema.hpp
@@ -153,7 +153,7 @@ public:
~json_validator();
json_validator &operator=(json_validator &&);
- // insert and set thea root-schema
+ // insert and set the root-schema
void set_root_schema(const json &);
// validate a json-document based on the root-schema
diff --git a/src/json-validator.cpp b/src/json-validator.cpp
index 5db8b23..8f6526b 100644
--- a/src/json-validator.cpp
+++ b/src/json-validator.cpp
@@ -171,6 +171,7 @@ public:
void set_root_schema(json schema)
{
+ files_.clear();
root_ = schema::make(schema, this, {}, {{"#"}});
// load all files which have not yet been loaded
@@ -225,7 +226,7 @@ public:
json instance_;
std::string message_;
- void error(const json::json_pointer & ptr, const json & instance, const std::string & message) override
+ void error(const json::json_pointer &ptr, const json &instance, const std::string &message) override
{
if (*this)
return;
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 5d08e41..b0ef6f5 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -21,8 +21,12 @@ endforeach()
add_executable(uri uri.cpp)
target_link_libraries(uri json-schema-validator)
+add_test(NAME uri COMMAND uri)
add_executable(errors errors.cpp)
target_link_libraries(errors json-schema-validator)
+add_test(NAME errors COMMAND errors)
-add_test(NAME uri COMMAND uri)
+add_executable(issue-70 issue-70.cpp)
+target_link_libraries(issue-70 json-schema-validator)
+add_test(NAME issue-70 COMMAND issue-70)
diff --git a/test/issue-70.cpp b/test/issue-70.cpp
new file mode 100644
index 0000000..7d42181
--- /dev/null
+++ b/test/issue-70.cpp
@@ -0,0 +1,44 @@
+#include