Fix setting enums that are typedefs

Issue: https://tree.taiga.io/project/jktjkt-netconf-cli/issue/64
Change-Id: Ibbeb8f6d89cfd0c104126d1bc3d7fbffc3aa3771
diff --git a/src/yang_schema.cpp b/src/yang_schema.cpp
index 57e66e5..7127082 100644
--- a/src/yang_schema.cpp
+++ b/src/yang_schema.cpp
@@ -115,7 +115,15 @@
         return false;
 
     libyang::Schema_Node_Leaf leaf(getSchemaNode(location, node));
-    const auto& enm = leaf.type()->info()->enums()->enm();
+    auto type = leaf.type();
+    auto enm = type->info()->enums()->enm();
+    // The enum can be a derived type and enm() only returns values,
+    // if that specific typedef changed the possible values. So we go
+    // up the hierarchy until we find a typedef that defined these values.
+    while (enm.empty()) {
+        type = type->der()->type();
+        enm = type->info()->enums()->enm();
+    }
 
     return std::any_of(enm.begin(), enm.end(), [=](const auto& x) { return x->name() == value; });
 }