Skip to content

Commit

Permalink
Nested output of properties in dict returned by parse_schema.
Browse files Browse the repository at this point in the history
  • Loading branch information
WyvernIXTL committed Jun 2, 2024
1 parent 89255f7 commit c5eaaa0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions installation_instruction/installation_instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,33 +73,34 @@ def parse_schema(self) -> dict:

result["title"] = self.schema.get("title", "")
result["description"] = self.schema.get("description", "")
result["properties"] = {}

for key, value in self.schema.get('properties', {}).items():

result[key] = {
result["properties"][key] = {
"title": value.get("title", key),
"description": value.get("description", ""),
"type": value.get("type", "enum"),
"default": value.get("default", None),
}
if "enum" in value:
result[key]["enum"] = [
result["properties"][key]["enum"] = [
{
"title": e,
"value": e,
"description": "",
} for e in value["enum"]
]
elif type := "anyOf" if "anyOf" in value else "oneOf" if "oneOf" in value else None:
result[key]["enum"] = [
result["properties"][key]["enum"] = [
{
"title": c.get("title", c.get("const", "")),
"value": c.get("const", ""),
"description": c.get("description", ""),
} for c in value[type]
]
else:
result[key]["type"] = "string"
result["properties"][key]["type"] = "string"

return result

Expand Down
4 changes: 2 additions & 2 deletions tests/test_installation_instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_parse_schema(test_data_flags_options):
schema = install.parse_schema()
print(schema)

assert schema["packager"] == {
assert schema["properties"]["packager"] == {
"title": "Packager",
"description": "The package manager of your choosing.",
"default": "pip",
Expand All @@ -41,7 +41,7 @@ def test_parse_schema(test_data_flags_options):
]
}

assert schema["compute_platform"] == {
assert schema["properties"]["compute_platform"] == {
"title": "Compute Platform",
"description": "Should your gpu or your cpu handle the task?",
"enum": [
Expand Down

0 comments on commit c5eaaa0

Please sign in to comment.