Skip to content

Commit 8125a3e

Browse files
committed
after et_root_schema, throw if there are undef refs
fix #97
1 parent c12a27e commit 8125a3e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/json-validator.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ class root_schema : public schema
239239
if (!new_schema_loaded) // if no new schema loaded, no need to try again
240240
break;
241241
} while (1);
242+
243+
for (const auto &file : files_)
244+
if (file.second.unresolved.size() != 0)
245+
throw std::invalid_argument("after all files have been parsed, '" +
246+
(file.first == "" ? "<root>" : file.first) +
247+
"' has still undefined references.");
242248
}
243249

244250
void validate(const json::json_pointer &ptr, const json &instance, json_patch &patch, error_handler &e) const final

test/issue-98.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ int main(void)
44
{
55
nlohmann::json nlBase{{"$ref", "#/unknown/keywords"}};
66
nlohmann::json_schema::json_validator validator;
7-
validator.set_root_schema(nlBase); // this line will log the caught exception
87

9-
return 0;
8+
try {
9+
validator.set_root_schema(nlBase); // this line will log the caught exception
10+
} catch (const std::exception &e) {
11+
if (std::string("after all files have been parsed, '<root>' has still undefined references.") == e.what())
12+
return EXIT_SUCCESS;
13+
}
14+
return EXIT_FAILURE;
1015
}

0 commit comments

Comments
 (0)