From 23423ba5c11e2a684220add6ea7f15abb2136218 Mon Sep 17 00:00:00 2001 From: Simon Lo Date: Wed, 6 Jun 2018 11:24:53 +0100 Subject: [PATCH] resolve "$ref" with relative uri correctly. fixes #9 --- src/json-uri.cpp | 4 +++- src/json-validator.cpp | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/json-uri.cpp b/src/json-uri.cpp index 5b737d3..2414b66 100644 --- a/src/json-uri.cpp +++ b/src/json-uri.cpp @@ -86,8 +86,10 @@ void json_uri::from_string(const std::string &uri) auto path = url.substr(pos); if (path[0] == '/') // if it starts with a / it is root-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); + } pointer_ = local_json_pointer(""); } diff --git a/src/json-validator.cpp b/src/json-validator.cpp index 5bfc809..1a7f1c1 100644 --- a/src/json-validator.cpp +++ b/src/json-validator.cpp @@ -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 std::shared_ptr schema = std::make_shared(input); - do { - // resolve all local schemas and references - resolver r(*schema, id); + // resolve all local schemas and local and external references + resolver r(*schema, id); + do { // check whether all undefined schema references can be resolved with existing ones std::set undefined; for (auto &ref : r.undefined_refs)