Extend json-schema model parser
Summary
For https://gitlab.indiscale.com/caosdb/customers/3dmmto/management/-/issues/9.
This implements
- pattern properties
- type null properties
- json schema references
- and json schemas without top-level recordtype specification
for the json schema datamodel parser.
Focus
Mainly additions to the JsonSchemaParser
class. We also defined a treatment for type: array
properties that lack a strict items
specification (i.e., could be lists of elements with mixed types, so a manual specification has to be provided -- or they are ignored altogether).
Test Environment
New unit tests. You can also test it with the chemotion json schema in nextcloud/Customers/3dmmto/example_files/testdaten_chemotion/schema.json
.
Check List for the Author
Please, prepare your MR for a review. Be sure to write a summary and a focus and create gitlab comments for the reviewer. They should guide the reviewer through the changes, explain your changes and also point out open questions. For further good practices have a look at our review guidelines
-
All automated tests pass -
Reference related issues -
Up-to-date CHANGELOG.md (or not necessary) -
Up-to-date JSON schema (or not necessary) -
Appropriate user and developer documentation (or not necessary) - How do I use the software? Assume "stupid" users.
- How do I develop or debug the software? Assume novice developers.
-
Annotations in code (Gitlab comments) - Intent of new code
- Problems with old code
- Why this implementation?
Check List for the Reviewer
-
I understand the intent of this MR -
All automated tests pass -
Up-to-date CHANGELOG.md (or not necessary) -
Appropriate user and developer documentation (or not necessary) -
The test environment setup works and the intended behavior is reproducible in the test environment -
In-code documentation and comments are up-to-date. -
Check: Are there specifications? Are they satisfied?
For further good practices have a look at our review guidelines.
Merge request reports
Activity
assigned to @florian
added 2 commits
added 2 commits
- Resolved by Timm Fitschen
- Resolved by Timm Fitschen
- Resolved by Timm Fitschen
- Resolved by Timm Fitschen
- Resolved by Timm Fitschen
- Resolved by Timm Fitschen
884 # List property will be an entity of its own with a name 885 # different from the referenced RT 886 ref_rt = self._treat_record_type( 887 items, self._stringify(items["title"])) 888 self.model[ref_rt.name] = ref_rt 889 return db.Property(name=name, datatype=db.LIST(ref_rt)), False 890 else: 891 # Use predefined type: 892 datatype = db.LIST(self.types_for_missing_array_items[name]) 796 893 return db.Property(name=name, datatype=datatype), False 797 if items["type"] == "object": 798 if "title" not in items or self._stringify(items["title"]) == name: 799 # Property is RecordType 800 return self._treat_record_type(items, name), True 894 895 def _get_pattern_prop(self): 920 if "title" not in element: 921 name_suffix = f"_{ii+1}" if num_patterns > 1 else "" 922 name = name_prefix + "Entry" + name_suffix 801 923 else: 802 # List property will be an entity of its own with a name 803 # different from the referenced RT 804 ref_rt = self._treat_record_type( 805 items, self._stringify(items["title"])) 806 self.model[ref_rt.name] = ref_rt 807 return db.Property(name=name, datatype=db.LIST(ref_rt)), False 924 name = element["title"] 925 if element["type"] == "object": 926 # simple, is already an object, so can be treated like any other 927 # record type. 928 pattern_type = self._treat_record_type(element, name) 929 elif element["type"] in JSON_SCHEMA_ATOMIC_TYPES: - src/doc/json_schema_interface.rst 0 → 100644
1 Defining datamodels with a JSON schema specification 2 ==================================================== 3 4 TODO, see https://gitlab.com/caosdb/caosdb-advanced-user-tools/-/issues/42