summaryrefslogtreecommitdiff
path: root/scripts/generate_schema_enums.py
diff options
context:
space:
mode:
authorChandramohan Harkude <chandramohan.harkude@gmail.com>2025-04-17 10:55:28 +0300
committerEd Tanous <ed@tanous.net>2025-04-21 18:36:12 +0300
commitd1a3caa4eda8ca07cd656b4e4e8aa1e4ffe53e1e (patch)
tree119e615feb2f39a3b4bd81a0e15176407262c3b2 /scripts/generate_schema_enums.py
parent6f5be43277a9225da2bf62138c59a698d426614f (diff)
downloadbmcweb-d1a3caa4eda8ca07cd656b4e4e8aa1e4ffe53e1e.tar.xz
Add TypeDefinition support for enumeration generation
TypeDefinition was not supported by generate_schema_enums.py, this change is to support the 'TypeDefinition' generation from schema. Tested: 'TypeDefinition' fields in schema can be generated in generated files with the change Change-Id: Ibe61f65b905f2089f9e17a26fbd27e3ff1753166 Signed-off-by: Chandramohan Harkude <chandramohan.harkude@gmail.com>
Diffstat (limited to 'scripts/generate_schema_enums.py')
-rwxr-xr-xscripts/generate_schema_enums.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/scripts/generate_schema_enums.py b/scripts/generate_schema_enums.py
index 44dcde6551..4f79f302b9 100755
--- a/scripts/generate_schema_enums.py
+++ b/scripts/generate_schema_enums.py
@@ -41,6 +41,14 @@ def parse_schema(element, filename):
for member in schema_element.findall(EDM + "Member"):
enums.append(member.attrib["Name"])
EntityTypes.append(Enum(name, enums, namespace, filename))
+ if schema_element.tag == EDM + "TypeDefinition":
+ enums = []
+ for annotation in schema_element:
+ for collection in annotation:
+ for record in collection.findall(EDM + "Record"):
+ for member in record.findall(EDM + "PropertyValue"):
+ enums.append(member.attrib["String"])
+ EntityTypes.append(Enum(name, enums, namespace, filename))
return EntityTypes
@@ -86,8 +94,13 @@ def write_enum_list(redfish_defs_file, enum_list, snake_case_namespace):
values.insert(0, "Invalid")
for value in values:
- redfish_defs_file.write(" {},\n".format(value))
+ # If the value is numeric, prefix it with the enum name
+ if value.isdigit():
+ enum_value = f"{element.name}{value}"
+ else:
+ enum_value = re.sub(r"[^0-9_a-zA-Z]", "", value)
+ redfish_defs_file.write(" {},\n".format(enum_value))
redfish_defs_file.write("};\n\n")
for element in enum_list:
@@ -102,8 +115,15 @@ def write_enum_list(redfish_defs_file, enum_list, snake_case_namespace):
"NLOHMANN_JSON_SERIALIZE_ENUM({}, {{\n".format(element.name)
)
for value in values:
+ # If the value is numeric, prefix it with the enum name
+ if value.isdigit():
+ enum_value = f"{element.name}{value}"
+ else:
+ enum_value = re.sub(r"[^0-9_a-zA-Z]", "", value)
redfish_defs_file.write(
- ' {{{}::{}, "{}"}},\n'.format(element.name, value, value)
+ ' {{{}::{}, "{}"}},\n'.format(
+ element.name, enum_value, value
+ )
)
redfish_defs_file.write("});\n\n")