From fb1f78d8fa445318e47fd21a3f078727a2b7b770 Mon Sep 17 00:00:00 2001 From: Daniel <d.hornung@indiscale.com> Date: Wed, 8 Nov 2023 09:29:22 +0100 Subject: [PATCH] ENH: json schema exporter: Removed "ID, " from reference enums. --- src/caosadvancedtools/json_schema_exporter.py | 2 +- unittests/test_json_schema_exporter.py | 36 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/caosadvancedtools/json_schema_exporter.py b/src/caosadvancedtools/json_schema_exporter.py index f950b06f..c836d56c 100644 --- a/src/caosadvancedtools/json_schema_exporter.py +++ b/src/caosadvancedtools/json_schema_exporter.py @@ -239,7 +239,7 @@ class JsonSchemaExporter: vals = [] for val in possible_values: if val.name: - vals.append(f"{val.id}, {val.name}") + vals.append(f"{val.name}") else: vals.append(f"{val.id}") diff --git a/unittests/test_json_schema_exporter.py b/unittests/test_json_schema_exporter.py index 95601ed9..e2772f55 100644 --- a/unittests/test_json_schema_exporter.py +++ b/unittests/test_json_schema_exporter.py @@ -337,11 +337,11 @@ def test_rt_with_references(): assert "oneOf" not in props["RefProp"] example = { - "RefProp": "101, otherB" + "RefProp": "otherB" } validate(example, schema) example = { - "RefProp": "23, I don't exist" + "RefProp": "I don't exist" } with raises(ValidationError): # Wrong enum value @@ -372,8 +372,8 @@ def test_rt_with_references(): assert "enum" in props["RefProp"]["oneOf"][enum_index] assert isinstance(props["RefProp"]["oneOf"][enum_index]["enum"], list) assert len(props["RefProp"]["oneOf"][enum_index]["enum"]) == 3 - assert "100, otherA" in props["RefProp"]["oneOf"][enum_index]["enum"] - assert "101, otherB" in props["RefProp"]["oneOf"][enum_index]["enum"] + assert "otherA" in props["RefProp"]["oneOf"][enum_index]["enum"] + assert "otherB" in props["RefProp"]["oneOf"][enum_index]["enum"] assert "102" in props["RefProp"]["oneOf"][enum_index]["enum"] # the other element of oneOf is the OtherType object assert props["RefProp"]["oneOf"][1 - enum_index]["type"] == "object" @@ -395,7 +395,7 @@ def test_rt_with_references(): validate(example, schema) example = { - "RefProp": "101, otherB", + "RefProp": "otherB", "OtherTextProp": "something" } validate(example, schema) @@ -423,17 +423,17 @@ def test_rt_with_references(): assert "description" not in items example = { - "RefProp": "101, otherB" + "RefProp": "otherB" } with raises(ValidationError): # Should be list but isn't validate(example, schema) example = { - "RefProp": ["101, otherB"] + "RefProp": ["otherB"] } validate(example, schema) example = { - "RefProp": ["101, otherB", "102", "104, referencing"] + "RefProp": ["otherB", "102", "referencing"] } validate(example, schema) @@ -461,8 +461,8 @@ def test_rt_with_references(): assert "enum" in items["oneOf"][enum_index] assert isinstance(items["oneOf"][enum_index]["enum"], list) assert len(items["oneOf"][enum_index]["enum"]) == 3 - assert "100, otherA" in items["oneOf"][enum_index]["enum"] - assert "101, otherB" in items["oneOf"][enum_index]["enum"] + assert "otherA" in items["oneOf"][enum_index]["enum"] + assert "otherB" in items["oneOf"][enum_index]["enum"] assert "102" in items["oneOf"][enum_index]["enum"] other_type = items["oneOf"][1 - enum_index] assert other_type["type"] == "object" @@ -472,7 +472,7 @@ def test_rt_with_references(): assert "IntegerProp" in other_type["required"] example = { - "RefProp": ["101, otherB", "102", "104, referencing"] + "RefProp": ["otherB", "102", "referencing"] } with raises(ValidationError): # Wrong value in enum @@ -488,7 +488,7 @@ def test_rt_with_references(): # we have additional_properties=False which propagates to subschemas validate(example, schema) example = { - "RefProp": [{"IntegerProp": 12}, "101, otherB"] + "RefProp": [{"IntegerProp": 12}, "otherB"] } validate(example, schema) @@ -506,7 +506,7 @@ def test_rt_with_references(): enum_index = 1 - enum_index assert len(ref_ref["oneOf"][enum_index]["enum"]) == 2 assert "103" in ref_ref["oneOf"][enum_index]["enum"] - assert "104, referencing" in ref_ref["oneOf"][enum_index]["enum"] + assert "referencing" in ref_ref["oneOf"][enum_index]["enum"] assert ref_ref["oneOf"][1 - enum_index]["type"] == "object" assert "OtherType" in ref_ref["oneOf"][1 - enum_index]["properties"] assert ref_ref["oneOf"][1 - enum_index]["properties"]["OtherType"]["type"] == "array" @@ -520,8 +520,8 @@ def test_rt_with_references(): assert "enum" in items["oneOf"][enum_index] assert isinstance(items["oneOf"][enum_index]["enum"], list) assert len(items["oneOf"][enum_index]["enum"]) == 3 - assert "100, otherA" in items["oneOf"][enum_index]["enum"] - assert "101, otherB" in items["oneOf"][enum_index]["enum"] + assert "otherA" in items["oneOf"][enum_index]["enum"] + assert "otherB" in items["oneOf"][enum_index]["enum"] assert "102" in items["oneOf"][enum_index]["enum"] other_type = items["oneOf"][1 - enum_index] assert other_type["type"] == "object" @@ -532,7 +532,7 @@ def test_rt_with_references(): example = { "RefRefProp": { "OtherType": [ - "100, otherA", + "otherA", {"IntegerProp": 12} ] } @@ -638,7 +638,7 @@ RT2: "title": "Existing entries", "enum": [ "103", - "104, referencing" + "referencing" ] }, { @@ -684,7 +684,7 @@ RT2: "description": "some description", "enum": [ "103", - "104, referencing" + "referencing" ] } }, -- GitLab