after et_root_schema, throw if there are undef refs

fix #97
This commit is contained in:
Patrick Boettcher 2020-05-15 09:33:26 +02:00
parent c12a27eee1
commit 8125a3e352
2 changed files with 13 additions and 2 deletions

View File

@ -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 == "" ? "<root>" : file.first) +
"' has still undefined references.");
}
void validate(const json::json_pointer &ptr, const json &instance, json_patch &patch, error_handler &e) const final

View File

@ -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, '<root>' has still undefined references.") == e.what())
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}