Add Schema::leaftypeName

Will be sued in the upcoming describe command.

Change-Id: I9ddecf8d3da1f82e8ce671210d51f31f895a9d27
diff --git a/src/schema.hpp b/src/schema.hpp
index 89a100c..ea0deba 100644
--- a/src/schema.hpp
+++ b/src/schema.hpp
@@ -77,6 +77,7 @@
     virtual const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const = 0;
     virtual yang::LeafDataTypes leafType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
     virtual yang::LeafDataTypes leafType(const std::string& path) const = 0;
+    virtual std::optional<std::string> leafTypeName(const std::string& path) const = 0;
     virtual yang::LeafDataTypes leafrefBaseType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
     virtual yang::LeafDataTypes leafrefBaseType(const std::string& path) const = 0;
     virtual std::string leafrefPath(const std::string& leafrefPath) const = 0;
diff --git a/src/static_schema.cpp b/src/static_schema.cpp
index 0eb564a..87d190a 100644
--- a/src/static_schema.cpp
+++ b/src/static_schema.cpp
@@ -305,3 +305,8 @@
 {
     throw std::runtime_error{"Internal error: StaticSchema::leafIsKey(std::string) not implemented. The tests should not have called this overload."};
 }
+
+std::optional<std::string> StaticSchema::leafTypeName([[maybe_unused]] const std::string& path) const
+{
+    throw std::runtime_error{"Internal error: StaticSchema::leafTypeName(std::string) not implemented. The tests should not have called this overload."};
+}
diff --git a/src/static_schema.hpp b/src/static_schema.hpp
index a3ab4bc..97f1e7e 100644
--- a/src/static_schema.hpp
+++ b/src/static_schema.hpp
@@ -58,6 +58,7 @@
     const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const override;
     yang::LeafDataTypes leafType(const schemaPath_& location, const ModuleNodePair& node) const override;
     yang::LeafDataTypes leafType(const std::string& path) const override;
+    std::optional<std::string> leafTypeName(const std::string& path) const override;
     yang::LeafDataTypes leafrefBaseType(const schemaPath_& location, const ModuleNodePair& node) const override;
     yang::LeafDataTypes leafrefBaseType(const std::string& path) const override;
     std::string leafrefPath(const std::string& leafrefPath) const override;
diff --git a/src/yang_schema.cpp b/src/yang_schema.cpp
index 0795b2b..d354069 100644
--- a/src/yang_schema.cpp
+++ b/src/yang_schema.cpp
@@ -290,6 +290,12 @@
     return impl_leafType(getSchemaNode(path));
 }
 
+std::optional<std::string> YangSchema::leafTypeName(const std::string& path) const
+{
+    libyang::Schema_Node_Leaf leaf(getSchemaNode(path));
+    return leaf.type()->der().get() ? std::optional{leaf.type()->der()->name()} : std::nullopt;
+}
+
 namespace {
 yang::LeafDataTypes impl_leafrefBaseType(const libyang::S_Schema_Node& node)
 {
diff --git a/src/yang_schema.hpp b/src/yang_schema.hpp
index 1165094..c763ea6 100644
--- a/src/yang_schema.hpp
+++ b/src/yang_schema.hpp
@@ -40,6 +40,7 @@
     const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const override;
     yang::LeafDataTypes leafType(const schemaPath_& location, const ModuleNodePair& node) const override;
     yang::LeafDataTypes leafType(const std::string& path) const override;
+    std::optional<std::string> leafTypeName(const std::string& path) const override;
     yang::LeafDataTypes leafrefBaseType(const schemaPath_& location, const ModuleNodePair& node) const override;
     yang::LeafDataTypes leafrefBaseType(const std::string& path) const override;
     std::string leafrefPath(const std::string& leafrefPath) const override;