From c5eaaa0d8ebaa049da97c9a59248ea7797be9ba6 Mon Sep 17 00:00:00 2001 From: Adam McKellar Date: Sun, 2 Jun 2024 18:11:15 +0200 Subject: [PATCH] Nested output of properties in dict returned by parse_schema. --- installation_instruction/installation_instruction.py | 9 +++++---- tests/test_installation_instruction.py | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/installation_instruction/installation_instruction.py b/installation_instruction/installation_instruction.py index ed1da48..6ea508f 100644 --- a/installation_instruction/installation_instruction.py +++ b/installation_instruction/installation_instruction.py @@ -73,17 +73,18 @@ 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, @@ -91,7 +92,7 @@ def parse_schema(self) -> dict: } 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", ""), @@ -99,7 +100,7 @@ def parse_schema(self) -> dict: } for c in value[type] ] else: - result[key]["type"] = "string" + result["properties"][key]["type"] = "string" return result diff --git a/tests/test_installation_instruction.py b/tests/test_installation_instruction.py index 8db8966..9e1ede1 100644 --- a/tests/test_installation_instruction.py +++ b/tests/test_installation_instruction.py @@ -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", @@ -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": [