diff --git a/components/common/cpp/include/ftl/configuration.hpp b/components/common/cpp/include/ftl/configuration.hpp index 9f8c6e0fda3033f0102b2ac1de95e7cb3afe3790..6cbd2ac379485978b5719277cf1a4dc1e1c7e209 100644 --- a/components/common/cpp/include/ftl/configuration.hpp +++ b/components/common/cpp/include/ftl/configuration.hpp @@ -103,12 +103,18 @@ T *ftl::config::create(json_t &link, ARGS ...args) { template <typename T, typename... ARGS> T *ftl::config::create(ftl::Configurable *parent, const std::string &name, ARGS ...args) { - nlohmann::json &entity = ftl::config::resolve(parent->getConfig()[name]); + //nlohmann::json &entity = ftl::config::resolve(parent->getConfig()[name]); + nlohmann::json &entity = (parent->getConfig()[name].is_structured()) ? parent->getConfig()[name] : ftl::config::resolve(parent->getConfig())[name]; if (entity.is_object()) { if (!entity["$id"].is_string()) { // TODO(Nick) Check for # in URI - entity["$id"] = *parent->get<std::string>("$id") + std::string("/") + name; + std::string id_str = *parent->get<std::string>("$id"); + if (id_str.find('#') != std::string::npos) { + entity["$id"] = id_str + std::string("/") + name; + } else { + entity["$id"] = id_str + std::string("#") + name; + } } } /*else { nlohmann::json &res = resolve(entity); diff --git a/components/common/cpp/src/configuration.cpp b/components/common/cpp/src/configuration.cpp index 07fad52d1021b8146d63722f36b157262b199148..31d8cd40891fc0b3f017ca58251828e54904f817 100644 --- a/components/common/cpp/src/configuration.cpp +++ b/components/common/cpp/src/configuration.cpp @@ -192,7 +192,12 @@ json_t &ftl::config::resolve(const std::string &puri) { // TODO(Nick) Must support alternative root (last $id) if (uri_str.at(0) == '#') { - uri_str = config["$id"].get<string>() + uri_str; + string id_str = config["$id"].get<string>(); + if (id_str.find('#') != string::npos) { + uri_str[0] = '/'; + } // else { + uri_str = id_str + uri_str; + //} } ftl::URI uri(uri_str); @@ -355,15 +360,18 @@ static void process_options(Configurable *root, const map<string, string> &opts) } try { - auto ptr = nlohmann::json::json_pointer("/"+opt.first); - // TODO(nick) Allow strings without quotes + //auto ptr = nlohmann::json::json_pointer("/"+opt.first); + auto ptr = ftl::config::resolve(*root->get<string>("$id") + string("/") + opt.first); + + LOG(INFO) << "PARAM RES TO " << (*root->get<string>("$id") + string("/") + opt.first); + auto v = nlohmann::json::parse(opt.second); - std::string type = root->getConfig().at(ptr).type_name(); + std::string type = ptr.type_name(); if (type != "null" && v.type_name() != type) { LOG(ERROR) << "Incorrect type for argument " << opt.first << " - expected '" << type << "', got '" << v.type_name() << "'"; continue; } - root->getConfig().at(ptr) = v; + ptr.update(v); } catch(...) { LOG(ERROR) << "Unrecognised option: " << *root->get<string>("$id") << "#" << opt.first; }