resolve "$ref" with relative uri correctly. fixes #9

This commit is contained in:
Simon Lo 2018-06-06 11:24:53 +01:00
parent e3d42e65c2
commit 23423ba5c1
2 changed files with 6 additions and 4 deletions

View File

@ -86,8 +86,10 @@ void json_uri::from_string(const std::string &uri)
auto path = url.substr(pos); auto path = url.substr(pos);
if (path[0] == '/') // if it starts with a / it is root-path if (path[0] == '/') // if it starts with a / it is root-path
path_ = path; path_ = path;
else // otherwise it is a subfolder else { // otherwise it is a relative-path
path_ = path_.substr(0, path_.find_last_of('/') + 1);
path_.append(path); path_.append(path);
}
pointer_ = local_json_pointer(""); pointer_ = local_json_pointer("");
} }

View File

@ -305,10 +305,10 @@ void json_validator::insert_schema(const json &input, const json_uri &id)
// allocate create a copy for later storage - if resolving reference works // allocate create a copy for later storage - if resolving reference works
std::shared_ptr<json> schema = std::make_shared<json>(input); std::shared_ptr<json> schema = std::make_shared<json>(input);
do { // resolve all local schemas and local and external references
// resolve all local schemas and references resolver r(*schema, id);
resolver r(*schema, id);
do {
// check whether all undefined schema references can be resolved with existing ones // check whether all undefined schema references can be resolved with existing ones
std::set<json_uri> undefined; std::set<json_uri> undefined;
for (auto &ref : r.undefined_refs) for (auto &ref : r.undefined_refs)