Skip to content
Snippets Groups Projects
Verified Commit de8de483 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

FIX: More json schema export fixes.

parent 6663bbaa
No related branches found
No related tags found
3 merge requests!138Release 0.14.0,!136JSON schema: List references, auto-detection of enums,!132Automatic XLSX export
Pipeline #63129 passed
...@@ -310,7 +310,9 @@ def test_export_lists(tmpdir): ...@@ -310,7 +310,9 @@ def test_export_lists(tmpdir):
training_props = schema_generated["properties"]["Training"]["properties"] training_props = schema_generated["properties"]["Training"]["properties"]
assert_equal_jsons(training_props["subjects"]["items"], assert_equal_jsons(training_props["subjects"]["items"],
{"type": ["string", "null"]}) {"type": ["string", "null"]})
assert training_props["subjects"]["uniqueItems"] is True if "oneOf" in training_props["coach"]["items"]:
raise ValueError("'coach' should be handled as 'do_not_retrieve', no records should "
"have been chosen.")
assert_equal_jsons(training_props["coach"]["items"]["properties"]["Organisation"], assert_equal_jsons(training_props["coach"]["items"]["properties"]["Organisation"],
{"enum": ["ECB", "IMF"]}) {"enum": ["ECB", "IMF"]})
assert_equal_jsons(training_props["supervisor"]["properties"]["Organisation"], assert_equal_jsons(training_props["supervisor"]["properties"]["Organisation"],
......
...@@ -272,8 +272,11 @@ ui_schema : dict ...@@ -272,8 +272,11 @@ ui_schema : dict
# Is this a multiple choice array? # Is this a multiple choice array?
multiple_choice = prop.name in self._multiple_choice multiple_choice = prop.name in self._multiple_choice
if not multiple_choice and self._multiple_choice_guess: # breakpoint()
if (not multiple_choice and self._multiple_choice_guess
and db.common.datatype.is_reference(list_element_prop.datatype)):
multiple_choice = self._guess_recordtype_is_enum(list_element_prop.datatype) multiple_choice = self._guess_recordtype_is_enum(list_element_prop.datatype)
# breakpoint()
# Get inner content of list # Get inner content of list
json_prop["items"], inner_ui_schema = self._make_segment_from_prop( json_prop["items"], inner_ui_schema = self._make_segment_from_prop(
...@@ -352,11 +355,17 @@ ui_schema : dict ...@@ -352,11 +355,17 @@ ui_schema : dict
# Find out if this property is an enum. # Find out if this property is an enum.
is_enum = (multiple_choice_enforce is_enum = (multiple_choice_enforce
or or
(self._do_not_retrieve == "auto" or self._multiple_choice_guess) (self._multiple_choice_guess
and self._guess_recordtype_is_enum(prop_name)) and self._guess_recordtype_is_enum(prop_name)))
# If `is_enum` -> always get values
# Otherwise -> `do_not_retrieve` may prevent retrieval
if is_enum or not ( if is_enum or not (
(
isinstance(self._do_not_retrieve, list) isinstance(self._do_not_retrieve, list)
and prop_name in self._do_not_retrieve): and prop_name in self._do_not_retrieve)
or (
self._do_not_retrieve == "auto"
)):
values = self._retrieve_enum_values(f"RECORD '{prop_name}'") values = self._retrieve_enum_values(f"RECORD '{prop_name}'")
else: else:
values = [] values = []
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment