Skip to content
Snippets Groups Projects
Commit a985bd7e authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

ENH: Add special treatment for name property

parent de7fd39a
Branches
Tags
2 merge requests!43REL: Release 0.4.1,!42ENH: Special treatment for name property
Pipeline #22412 passed with warnings
......@@ -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)
......
......@@ -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.")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment