diff --git a/src/caosadvancedtools/json_schema_exporter.py b/src/caosadvancedtools/json_schema_exporter.py index 5daa5a4ec0543a4ff00c7512e22598b6fe0d50ae..7a92eaad8aeb55ae5c34e529de4848ce4a12b0f9 100644 --- a/src/caosadvancedtools/json_schema_exporter.py +++ b/src/caosadvancedtools/json_schema_exporter.py @@ -58,8 +58,9 @@ from collections import OrderedDict from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, Union import linkahead as db -from linkahead.cached import cached_query, cache_clear +from linkahead.cached import cache_clear, cached_query from linkahead.common.datatype import get_list_datatype, is_list_datatype + from .models.data_model import DataModel @@ -322,6 +323,10 @@ ui_schema : dict rt = results[0] else: rt = db.Entity() + + if isinstance(rt, str): + raise NotImplementedError("Behavior is not implemented when _no_remote == True and datatype is given as a string.") + subschema, ui_schema = self._make_segment_from_recordtype(rt) if prop.is_reference(): if prop.name: @@ -431,6 +436,7 @@ ui_schema : dict } } """ + schema: OrderedDict[str, Any] = OrderedDict({ "type": "object" }) diff --git a/unittests/test_json_schema_exporter.py b/unittests/test_json_schema_exporter.py index fd6dbf7cd115068c2c172b33a25a24f33a6d373c..3b37f638fc0115fd47757e3bb0afb52c84b66b3e 100644 --- a/unittests/test_json_schema_exporter.py +++ b/unittests/test_json_schema_exporter.py @@ -23,18 +23,16 @@ """Tests the Json schema exporter.""" import json - -import linkahead as db -import caosadvancedtools.json_schema_exporter as jsex - from collections import OrderedDict - -from jsonschema import FormatChecker, validate, ValidationError -from pytest import raises from unittest.mock import Mock, patch -from caosadvancedtools.json_schema_exporter import recordtype_to_json_schema as rtjs +import caosadvancedtools.json_schema_exporter as jsex +import linkahead as db +from caosadvancedtools.json_schema_exporter import \ + recordtype_to_json_schema as rtjs from caosadvancedtools.models.parser import parse_model_from_string +from jsonschema import FormatChecker, ValidationError, validate +from pytest import raises GLOBAL_MODEL = parse_model_from_string(""" RT1: @@ -920,10 +918,12 @@ RT3: schema_noexist = rtjs(model.get_deep("RT3")) assert schema_noexist["properties"]["NoRecords"].get("type") == "object" - schema_noexist_noremote = rtjs(model.get_deep("RT3"), no_remote=True) - assert schema_noexist_noremote["properties"]["NoRecords"].get("type") == "object" - assert (schema_noexist_noremote["properties"]["NoRecords"].get("properties") - == OrderedDict([('some_text', {'type': 'string'})])) + with raises(NotImplementedError, + match="Behavior is not implemented when _no_remote == True and datatype is given as a string."): + schema_noexist_noremote = rtjs(model.get_deep("RT3"), no_remote=True) + assert schema_noexist_noremote["properties"]["NoRecords"].get("type") == "object" + assert (schema_noexist_noremote["properties"]["NoRecords"].get("properties") + == OrderedDict([('some_text', {'type': 'string'})])) uischema = {} schema_noexist_noretrieve = rtjs(model.get_deep("RT2"), do_not_retrieve=["RT1"],