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

ENH: Raise error in case of multiprops

parent 5b8df05b
No related branches found
No related tags found
2 merge requests!89ENH: JsonSchemaExporter accepts do_not_create parameter.,!80F simple schema export
Pipeline #42157 failed
......@@ -94,7 +94,7 @@ def _make_prop_from_prop(prop, additional_options_for_text_props):
json_prop["type"] = "integer"
elif prop.datatype == db.DOUBLE:
json_prop["type"] = "number"
elif prop.datatype.startswith("LIST"):
elif isinstance(prop.datatype, str) and prop.datatype.startswith("LIST"):
json_prop["type"] = "array"
list_element_prop = db.Property(
name=prop.name, datatype=_extract_elemet_dtyp_from_list_dtype(prop.datatype))
......@@ -170,6 +170,12 @@ def recordtype_to_json_schema(rt: db.RecordType, additional_properties: bool = T
props["description"] = _make_text_property("The description of the Record to be created")
for prop in rt.properties:
if prop.name in props:
# Multi property
raise NotImplementedError(
"Creating a schema for multi-properties is not specified. "
f"Property {prop.name} occurs more than once."
)
props[prop.name] = _make_prop_from_prop(prop, additional_options_for_text_props)
schema["properties"] = props
......
......@@ -232,3 +232,24 @@ def test_rt_with_references():
with raises(NotImplementedError):
rtjs(rt)
def test_broken():
rt = db.RecordType()
rt.add_property(name="something", datatype=None)
with raises(ValueError) as ve:
rtjs(rt)
assert str(ve).startswith("Unknown or no property datatype.")
rt = db.RecordType()
rt.add_property(name="MultiProp", datatype=db.INTEGER)
rt.add_property(name="MultiProp", datatype=db.INTEGER)
with raises(NotImplementedError) as nie:
rtjs(rt)
assert "MultiProp" in str(nie)
assert str(nie).startswith("Creating a schema for multi-properties is not specified.")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment