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

MAINT: Renamed a few functions.

parent a4e990c8
No related branches found
No related tags found
2 merge requests!89ENH: JsonSchemaExporter accepts do_not_create parameter.,!81F schema export references
......@@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Parsing from YAML now allows to give an existing model to which the YAML data model shall be
added.
* The `json_schema_exporter` module which introduces tools to create a json
schema from a RecordType, e.g., for the useage in web forms.
schema from a RecordType, e.g., for the usage in web forms.
### Changed ###
......
......@@ -34,7 +34,8 @@ Optional h5-crawler:
## Run Unit Tests
- All tests: `tox`
- One specific test: `tox -- -k expression`
- One specific test with tox: `tox -- unittests/test_myusecase.py -k expression`
- Or even using only pytest: `pytest unittests/test_myusecase.py -k expression`
## Run Integration Tests Locally
......
......@@ -33,10 +33,10 @@ def _make_required_list(rt: db.RecordType):
if rt.get_importance(prop.name) == db.OBLIGATORY]
def _make_prop_from_prop(prop: db.Property, additional_properties: bool,
name_and_description_in_properties: bool,
additional_options_for_text_props: Optional[dict],
units_in_description: bool):
def _make_segment_from_prop(prop: db.Property, additional_properties: bool,
name_and_description_in_properties: bool,
additional_options_for_text_props: Optional[dict],
units_in_description: bool):
"""Return the JSON Schema segment for the given property
Parameters
......@@ -44,7 +44,7 @@ def _make_prop_from_prop(prop: db.Property, additional_properties: bool,
prop : db.Property
the property to be transformed
additional_properties : bool, optional
Whether additional propeties will be admitted in the resulting
Whether additional properties will be admitted in the resulting
schema. Optional, default is True.
name_and_description_in_properties : bool, optional
Whether to include name and description in the `properties` section of
......@@ -99,7 +99,7 @@ def _make_prop_from_prop(prop: db.Property, additional_properties: bool,
json_prop["type"] = "array"
list_element_prop = db.Property(
name=prop.name, datatype=get_list_datatype(prop.datatype, strict=True))
json_prop["items"] = _make_prop_from_prop(
json_prop["items"] = _make_segment_from_prop(
list_element_prop, additional_properties,
name_and_description_in_properties, additional_options_for_text_props,
units_in_description
......@@ -116,10 +116,10 @@ def _make_prop_from_prop(prop: db.Property, additional_properties: bool,
else:
values = _retrieve_enum_values(f"RECORD '{prop.datatype}'")
rt = db.execute_query(f"FIND RECORDTYPE WITH name='{prop.datatype}'", unique=True)
subschema = _treat_recordtype(rt, additional_properties,
name_and_description_in_properties,
additional_options_for_text_props,
units_in_description)
subschema = _make_segment_from_recordtype(rt, additional_properties,
name_and_description_in_properties,
additional_options_for_text_props,
units_in_description)
json_prop["oneOf"] = [
{"enum": values},
subschema
......@@ -167,9 +167,7 @@ def _retrieve_enum_values(role: str):
possible_values = db.execute_query(f"SELECT name, id FROM {role}")
vals = []
for val in possible_values:
if val.name:
vals.append(f"{val.id}, {val.name}")
else:
......@@ -178,10 +176,12 @@ def _retrieve_enum_values(role: str):
return vals
def _treat_recordtype(rt: db.RecordType, additional_properties: bool = True,
name_and_description_in_properties: bool = False,
additional_options_for_text_props: Optional[dict] = None,
units_in_description: bool = True):
def _make_segment_from_recordtype(rt: db.RecordType, additional_properties: bool = True,
name_and_description_in_properties: bool = False,
additional_options_for_text_props: Optional[dict] = None,
units_in_description: bool = True):
"""Return a Json schema segment for the given RecordType.
"""
schema = {
"type": "object"
}
......@@ -201,7 +201,7 @@ def _treat_recordtype(rt: db.RecordType, additional_properties: bool = True,
"Creating a schema for multi-properties is not specified. "
f"Property {prop.name} occurs more than once."
)
props[prop.name] = _make_prop_from_prop(
props[prop.name] = _make_segment_from_prop(
prop, additional_properties, name_and_description_in_properties,
additional_options_for_text_props, units_in_description)
......@@ -246,8 +246,10 @@ def recordtype_to_json_schema(rt: db.RecordType, additional_properties: bool = T
if additional_options_for_text_props is None:
additional_options_for_text_props = {}
schema = _treat_recordtype(rt, additional_properties, name_and_description_in_properties,
additional_options_for_text_props, units_in_description)
schema = _make_segment_from_recordtype(rt, additional_properties,
name_and_description_in_properties,
additional_options_for_text_props,
units_in_description)
schema["$schema"] = "https://json-schema.org/draft/2019-09/schema"
if rt.name:
schema["title"] = rt.name
......
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