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 + +using nlohmann::json; +using nlohmann::json_schema::json_validator; + +static const json person_schema = R"( +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "A person", + "properties": { + "name": { + "description": "Name", + "type": "string" + }, + "age": { + "description": "Age of the person", + "type": "number", + "minimum": 2, + "maximum": 200 + }, + "phones": { + "type": "array", + "items": { + "type": "number" + } + } + }, + "required": [ + "name", + "age" + ], + "additionalProperties": false, + "type": "object" +})"_json; + +int main(void) +{ + json_validator validator; + + validator.set_root_schema(person_schema); + validator.set_root_schema(person_schema); + + return 0; +}