diff --git a/src/json-validator.cpp b/src/json-validator.cpp index 62bac0a..f16f3ef 100644 --- a/src/json-validator.cpp +++ b/src/json-validator.cpp @@ -239,6 +239,12 @@ public: if (!new_schema_loaded) // if no new schema loaded, no need to try again break; } while (1); + + for (const auto &file : files_) + if (file.second.unresolved.size() != 0) + throw std::invalid_argument("after all files have been parsed, '" + + (file.first == "" ? "" : file.first) + + "' has still undefined references."); } void validate(const json::json_pointer &ptr, const json &instance, json_patch &patch, error_handler &e) const final diff --git a/test/issue-98.cpp b/test/issue-98.cpp index 7aafe47..088b324 100644 --- a/test/issue-98.cpp +++ b/test/issue-98.cpp @@ -4,7 +4,12 @@ int main(void) { nlohmann::json nlBase{{"$ref", "#/unknown/keywords"}}; nlohmann::json_schema::json_validator validator; - validator.set_root_schema(nlBase); // this line will log the caught exception - return 0; + try { + validator.set_root_schema(nlBase); // this line will log the caught exception + } catch (const std::exception &e) { + if (std::string("after all files have been parsed, '' has still undefined references.") == e.what()) + return EXIT_SUCCESS; + } + return EXIT_FAILURE; }