Skip to content
Snippets Groups Projects

ENH: add framework for converting json schema into table templates

Merged Henrik tom Wörden requested to merge f-more-jsonschema-export into dev
29 files
+ 1736
39
Compare changes
  • Side-by-side
  • Inline
Files
29
@@ -20,9 +20,12 @@
@@ -20,9 +20,12 @@
# with this program. If not, see <https://www.gnu.org/licenses/>.
# with this program. If not, see <https://www.gnu.org/licenses/>.
#
#
 
import json
 
import linkahead as db
import linkahead as db
from caosadvancedtools.json_schema_exporter import recordtype_to_json_schema as rtjs
from caosadvancedtools.json_schema_exporter import recordtype_to_json_schema as rtjs
 
from caosadvancedtools.models.parser import parse_model_from_string
def _delete_everything():
def _delete_everything():
@@ -75,3 +78,37 @@ def test_uniqueness_of_reference_types():
@@ -75,3 +78,37 @@ def test_uniqueness_of_reference_types():
assert one_of[1 - enum_index]["type"] == "object"
assert one_of[1 - enum_index]["type"] == "object"
# No properties in parent_type
# No properties in parent_type
assert len(one_of[1 - enum_index]["properties"]) == 0
assert len(one_of[1 - enum_index]["properties"]) == 0
 
 
 
def test_reference_property():
 
model_string = """
 
RT1:
 
description: Some recordtype
 
RT2:
 
obligatory_properties:
 
prop1:
 
description: Some reference property
 
datatype: RT1
 
"""
 
model = parse_model_from_string(model_string)
 
model.sync_data_model(noquestion=True)
 
schema = rtjs(db.RecordType(name="RT2").retrieve())
 
assert json.dumps(schema, indent=2) == """{
 
"type": "object",
 
"required": [
 
"prop1"
 
],
 
"additionalProperties": true,
 
"title": "RT2",
 
"properties": {
 
"prop1": {
 
"type": "object",
 
"required": [],
 
"additionalProperties": true,
 
"description": "Some reference property",
 
"title": "prop1",
 
"properties": {}
 
}
 
},
 
"$schema": "https://json-schema.org/draft/2020-12/schema"
 
}"""
Loading