diff --git a/src/caosadvancedtools/models/parser.py b/src/caosadvancedtools/models/parser.py index 3cc370f4908ad87907a100a69d4122053b88f8b5..5848a5e786cb975df06ab5ae5c439ce55d50bb97 100644 --- a/src/caosadvancedtools/models/parser.py +++ b/src/caosadvancedtools/models/parser.py @@ -181,7 +181,7 @@ def parse_model_from_json_schema(filename: str, top_level_recordtype: bool = Tru # @review Daniel Hornung 2022-02-18 parser = JsonSchemaParser() - return parser.parse_model_from_json_schema(filename) + return parser.parse_model_from_json_schema(filename, top_level_recordtype) class Parser(object): diff --git a/unittests/json-schema-models/datamodel_no_toplevel_entity.schema.json b/unittests/json-schema-models/datamodel_no_toplevel_entity.schema.json new file mode 100644 index 0000000000000000000000000000000000000000..d8d0369a613f97360488224f925b1f436b982429 --- /dev/null +++ b/unittests/json-schema-models/datamodel_no_toplevel_entity.schema.json @@ -0,0 +1,40 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://my-schema-id.net", + "type": "object", + "definitions": { + "uuid": { + "type": [ + "string", + "null" + ], + "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" + }, + "datetime": { + "type": "string", + "format": "date-time" + } + }, + "properties": { + { + "title": "Dataset1", + "description": "Some description", + "type": "object", + "properties": { + "title": { + "type": "string", + "description": "full dataset title" + }, + "campaign": { + "type": "string", + "description": "FIXME" + }, + "number_prop": { + "type": "number", + "description": "Some float property" + } + }, + "required": ["title", "number_prop"] + } + } +} diff --git a/unittests/test_json_schema_model_parser.py b/unittests/test_json_schema_model_parser.py index a136f9ba2ae9965978c7f1234acb16289a3ca305..adc6361c08787cee081b08984d35233cb4e8659b 100644 --- a/unittests/test_json_schema_model_parser.py +++ b/unittests/test_json_schema_model_parser.py @@ -356,3 +356,8 @@ def test_name_property(): assert str(err.value).startswith( "The 'name' property must be string-typed, otherwise it cannot be identified with CaosDB's " "name property.") + + +def test_no_toplevel_entity(): + model = parse_model_from_json_schema(os.path.join( + FILEPATH, "datamodel_no_toplevel_entity.schema.json"), top_level_recordtype=False)