diff --git a/src/caosadvancedtools/models/parser.py b/src/caosadvancedtools/models/parser.py index 48fc1e722c4ce9e888b8b80dbb5f29595c2f6b26..4d5730e58bc472b5da830bdb67c9127d5a4b0377 100644 --- a/src/caosadvancedtools/models/parser.py +++ b/src/caosadvancedtools/models/parser.py @@ -566,9 +566,11 @@ class Parser(object): db.BOOLEAN]: if is_list: - value.datatype = db.LIST(db.__getattribute__(dtype)) # pylint: disable=no-member + value.datatype = db.LIST(db.__getattribute__( + dtype)) # pylint: disable=no-member else: - value.datatype = db.__getattribute__(dtype) # pylint: disable=no-member + value.datatype = db.__getattribute__( + dtype) # pylint: disable=no-member continue @@ -692,6 +694,15 @@ class JsonSchemaParser(Parser): # Each element must have a specific type raise JsonSchemaDefinitionError( f"`type` is missing in element {name}.") + if name == "name": + # This is identified with the CaosDB name property as long as the + # type is correct. + if not elt["type"] == "string": + raise JsonSchemaDefinitionError( + "The 'name' property must be string-typed, otherwise it cannot " + "be identified with CaosDB's name property." + ) + return None, force_list if "enum" in elt: ent = self._treat_enum(elt, name) elif elt["type"] in JSON_SCHEMA_ATOMIC_TYPES: @@ -726,6 +737,10 @@ class JsonSchemaParser(Parser): else: name = self._stringify(key) prop_ent, force_list = self._treat_element(prop, name) + if prop_ent is None: + # Nothing to be appended since the property has to be + # treated specially. + continue importance = db.OBLIGATORY if key in required else db.RECOMMENDED if not force_list: rt.add_property(prop_ent, importance=importance) diff --git a/unittests/test_json_schema_model_parser.py b/unittests/test_json_schema_model_parser.py index 061d9299028235d5db07c8e144b7d707aa1a0671..c5dbcf532d4ee6a0f4d4aa6edca9841e1d69ce8a 100644 --- a/unittests/test_json_schema_model_parser.py +++ b/unittests/test_json_schema_model_parser.py @@ -350,8 +350,8 @@ def test_name_property(): assert dataset_rt.get_property("name") is None assert "name" not in model - with pytest.raises(ValueError) as err: + with pytest.raises(JsonSchemaDefinitionError) as err: broken = parse_model_from_json_schema(os.path.join( FILEPATH, "datamodel_name_wrong_type.schema.json")) assert str(err.value).startswith( - "The 'name' property of Dataset must be string-typed, otherwise it cannot be identified with CaosDB's name property.") + "The 'name' property must be string-typed, otherwise it cannot be identified with CaosDB's name property.")