Unify childNodes between YANG and static Schema
childNodes in YangSchema doesn't include module node prefixes when they
were the same as the top-level module, but StaticSchema always included
them. This changes StaticSchema to work the same as YangSchema does.
This change is good, because the tests for completion are now more
accurate.
Change-Id: I8378c22775d0a3bc66fe5e574dd0a0abfd0eeb15
diff --git a/src/static_schema.cpp b/src/static_schema.cpp
index 082d03b..d554cb9 100644
--- a/src/static_schema.cpp
+++ b/src/static_schema.cpp
@@ -162,15 +162,32 @@
return res;
}
- std::string locationString =
- path.type() == typeid(schemaPath_) ?
- pathToSchemaString(boost::get<schemaPath_>(path), Prefixes::Always) :
- pathToSchemaString(boost::get<dataPath_>(path), Prefixes::Always);
+ auto getTopLevelModule = [] (const auto& path) -> boost::optional<std::string> {
+ if (!path.m_nodes.empty()) {
+ return path.m_nodes.begin()->m_prefix.flat_map([] (const auto& module) {return boost::optional<std::string>(module.m_name);});
+ }
+
+ return boost::none;
+ };
+
+ std::string locationString;
+ boost::optional<std::string> topLevelModule;
+ if (path.type() == typeid(schemaPath_)) {
+ locationString = pathToSchemaString(boost::get<schemaPath_>(path), Prefixes::Always);
+ topLevelModule = getTopLevelModule(boost::get<schemaPath_>(path));
+ } else {
+ locationString = pathToSchemaString(boost::get<dataPath_>(path), Prefixes::Always);
+ topLevelModule = getTopLevelModule(boost::get<dataPath_>(path));
+ }
auto childrenRef = children(locationString);
- std::transform(childrenRef.begin(), childrenRef.end(), std::inserter(res, res.end()), [](const auto& it) {
- return splitModuleNode(it.first);
+ std::transform(childrenRef.begin(), childrenRef.end(), std::inserter(res, res.end()), [path, topLevelModule](const auto& it) {
+ auto res = splitModuleNode(it.first);
+ if (topLevelModule == res.first) {
+ res.first = boost::none;
+ }
+ return res;
});
return res;
}