sdbus++: common: allow empty path segment values
A missing 'value' would crash in a path YAML would crash the
generator. Change this so it doesn't crash, but throws an
exception for a non-segment path. For a path segment, we can
turn the 'name' into a path segment with `snake_case`.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I16c8bc30f0b75359d3105c0d8035554cc381ceee
diff --git a/tools/sdbusplus/path.py b/tools/sdbusplus/path.py
index c3a9e13..0533b70 100644
--- a/tools/sdbusplus/path.py
+++ b/tools/sdbusplus/path.py
@@ -15,11 +15,14 @@
kwargs["name"] = "InstancePath"
self.value = kwargs.pop("instance")
else:
- self.value = kwargs.pop("value", False)
+ self.value = kwargs.pop("value", "")
# Validate path/segment format.
if len(self.value) == 0:
- raise ValueError("Invalid empty path.")
+ if segment:
+ self.value = NamedElement(name=kwargs["name"]).snake_case
+ else:
+ raise ValueError("Invalid empty path.")
if not segment and self.value[0] != "/":
raise ValueError(f"Paths must start with /: {self.value}")
if segment and self.value[0] == "/":