From cd9459b238ccabdd1c03c3f80eca0d2763e40d4d Mon Sep 17 00:00:00 2001 From: Daniel <d.hornung@indiscale.com> Date: Mon, 6 Nov 2023 11:57:46 +0100 Subject: [PATCH] ENH: Split up name_and_description_in_properties in two parameters. --- src/caosadvancedtools/json_schema_exporter.py | 33 ++++++++++++------- unittests/test_json_schema_exporter.py | 7 ++-- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/caosadvancedtools/json_schema_exporter.py b/src/caosadvancedtools/json_schema_exporter.py index 01e0c76e..4c06d6ff 100644 --- a/src/caosadvancedtools/json_schema_exporter.py +++ b/src/caosadvancedtools/json_schema_exporter.py @@ -36,7 +36,8 @@ class JsonSchemaExporter: """ def __init__(self, additional_properties: bool = True, - name_and_description_in_properties: bool = False, + name_for_new_reference_records: bool = False, + description_for_new_reference_records: bool = False, additional_options_for_text_props: dict = None, units_in_description: bool = True, do_not_create: List[str] = None, @@ -50,9 +51,12 @@ class JsonSchemaExporter: additional_properties : bool, optional Whether additional properties will be admitted in the resulting schema. Optional, default is True. - name_and_description_in_properties : bool, optional - Whether objects that are generated from reference properties shall have a `name` and - `description` property in the generated schema. Optional, default is False. + name_for_new_reference_records : bool, optional + Whether objects that are generated from reference properties shall have a `name` + property in the generated schema. Optional, default is False. + description_for_new_reference_records : bool, optional + Whether objects that are generated from reference properties shall have a `description` + property in the generated schema. Optional, default is False. additional_options_for_text_props : dict, optional Dictionary containing additional "pattern" or "format" options for string-typed properties. Optional, default is empty. @@ -80,7 +84,8 @@ class JsonSchemaExporter: do_not_retrieve = [] self._additional_properties = additional_properties - self._name_and_description_in_properties = name_and_description_in_properties + self._name_for_new_reference_records = name_for_new_reference_records + self._description_for_new_reference_records = description_for_new_reference_records self._additional_options_for_text_props = additional_options_for_text_props self._units_in_description = units_in_description self._do_not_create = do_not_create @@ -251,8 +256,9 @@ class JsonSchemaExporter: schema["additionalProperties"] = self._additional_properties props = OrderedDict() - if self._name_and_description_in_properties: + if self._name_for_new_reference_records: props["name"] = self._make_text_property("The name of the Record to be created") + if self._description_for_new_reference_records: props["description"] = self._make_text_property( "The description of the Record to be created") @@ -297,7 +303,8 @@ class JsonSchemaExporter: def recordtype_to_json_schema(rt: db.RecordType, additional_properties: bool = True, - name_and_description_in_properties: bool = False, + name_for_new_reference_records: bool = False, + description_for_new_reference_records: bool = False, additional_options_for_text_props: Optional[dict] = None, units_in_description: bool = True, do_not_create: List[str] = None, @@ -317,9 +324,12 @@ def recordtype_to_json_schema(rt: db.RecordType, additional_properties: bool = T additional_properties : bool, optional Whether additional properties will be admitted in the resulting schema. Optional, default is True. - name_and_description_in_properties : bool, optional - Whether objects that are generated from reference properties shall have a `name` and - `description` property in the generated schema. Optional, default is False. + name_for_new_reference_records : bool, optional + Whether objects that are generated from reference properties shall have a `name` + property in the generated schema. Optional, default is False. + description_for_new_reference_records : bool, optional + Whether objects that are generated from reference properties shall have a `description` + property in the generated schema. Optional, default is False. additional_options_for_text_props : dict, optional Dictionary containing additional "pattern" or "format" options for string-typed properties. Optional, default is empty. @@ -348,7 +358,8 @@ def recordtype_to_json_schema(rt: db.RecordType, additional_properties: bool = T exporter = JsonSchemaExporter( additional_properties=additional_properties, - name_and_description_in_properties=name_and_description_in_properties, + name_for_new_reference_records=name_for_new_reference_records, + description_for_new_reference_records=description_for_new_reference_records, additional_options_for_text_props=additional_options_for_text_props, units_in_description=units_in_description, do_not_create=do_not_create, diff --git a/unittests/test_json_schema_exporter.py b/unittests/test_json_schema_exporter.py index 68627e16..86a40baa 100644 --- a/unittests/test_json_schema_exporter.py +++ b/unittests/test_json_schema_exporter.py @@ -112,7 +112,8 @@ def test_empty_rt(): assert len(schema["required"]) == 0 assert schema["additionalProperties"] is False - schema = rtjs(rt, name_and_description_in_properties=True) + schema = rtjs(rt, name_for_new_reference_records=True, + description_for_new_reference_records=True) assert len(schema["properties"]) == 2 assert "name" in schema["properties"] @@ -439,8 +440,8 @@ def test_rt_with_references(): rt = db.RecordType() rt.add_property(name="RefProp", datatype=db.LIST("OtherType")) - schema = rtjs(rt, additional_properties=False, - name_and_description_in_properties=True) + schema = rtjs(rt, additional_properties=False, name_for_new_reference_records=True, + description_for_new_reference_records=True) assert schema["additionalProperties"] is False assert "name" in schema["properties"] assert schema["properties"]["name"]["type"] == "string" -- GitLab