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

FIX: jsex: handle reference properties better

parent dceda2b7
No related branches found
No related tags found
3 merge requests!100WIP: Filling XLSX: Seems to be working.,!94ENH: add framework for converting json schema into table templates,!93Filling XLSX: Everything except multiple choice.
Pipeline #44649 passed
......@@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ###
- Json schema exporter handles reference properties better.
### Security ###
### Documentation ###
......
......@@ -20,9 +20,12 @@
# with this program. If not, see <https://www.gnu.org/licenses/>.
#
import json
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
def _delete_everything():
......@@ -75,3 +78,37 @@ def test_uniqueness_of_reference_types():
assert one_of[1 - enum_index]["type"] == "object"
# No properties in parent_type
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"
}"""
......@@ -272,6 +272,12 @@ class JsonSchemaExporter:
rt = db.execute_query(f"FIND RECORDTYPE WITH name='{prop_name}'",
unique=True)
subschema, ui_schema = self._make_segment_from_recordtype(rt)
if prop.is_reference():
if prop.name:
subschema["title"] = prop.name
if prop.description:
subschema["description"] = prop.description
# if inner_ui_schema:
# ui_schema = inner_ui_schema
if values:
......
......@@ -598,6 +598,38 @@ def test_rt_with_references():
assert items["properties"]["file"]["type"] == "string"
assert items["properties"]["file"]["format"] == "data-url"
# 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)
schema = rtjs(model.get_deep("RT2"), no_remote=True)
assert json.dumps(schema, indent=2) == """{
"type": "object",
"required": [
"RT1"
],
"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"
}"""
def test_broken():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment