From 448faa36abbc9916ee639dc9b66bf3ab02a98a25 Mon Sep 17 00:00:00 2001 From: Daniel <d.hornung@indiscale.com> Date: Mon, 27 Nov 2023 18:24:17 +0100 Subject: [PATCH] ENH: jsex has new parameter `use_rt_pool` --- CHANGELOG.md | 2 ++ src/caosadvancedtools/json_schema_exporter.py | 25 +++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b6446ab..685ff7cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### +- Json schema exporter has new parameter `use_rt_pool`. + ### Changed ### ### Deprecated ### diff --git a/src/caosadvancedtools/json_schema_exporter.py b/src/caosadvancedtools/json_schema_exporter.py index 700c24e8..666ecfdc 100644 --- a/src/caosadvancedtools/json_schema_exporter.py +++ b/src/caosadvancedtools/json_schema_exporter.py @@ -29,6 +29,7 @@ from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, Union import linkahead as db from linkahead.common.datatype import get_list_datatype, is_list_datatype +from .models.data_model import DataModel class JsonSchemaExporter: @@ -45,6 +46,7 @@ class JsonSchemaExporter: do_not_create: List[str] = None, do_not_retrieve: List[str] = None, no_remote: bool = False, + use_rt_pool: DataModel = None, multiple_choice: List[str] = None, wrap_files_in_objects: bool = False, ): @@ -73,16 +75,21 @@ class JsonSchemaExporter: description of the corresponding schema entry. If set to false, an additional `unit` key is added to the schema itself which is purely annotational and ignored, e.g., in validation. Default is True. - do_not_create : list[str] + do_not_create : list[str], optional A list of reference Property names, for which there should be no option to create them. Instead, only the choice of existing elements should be given. - do_not_retrieve : list[str] + do_not_retrieve : list[str], optional A list of RedcordType names, for which no Records shall be retrieved. Instead, only an object description should be given. If this list overlaps with the `do_not_create` parameter, the behavior is undefined. - no_remote : bool - If True, do not attempt to connect to a LinkAhead server at all. Default is False. + no_remote : bool, optional + If True, do not attempt to connect to a LinkAhead server at all. Default is False. Note + that the exporter may fail if this option is activated and the data model is not + self-sufficient. + use_rt_pool : DataModel, optional + If given, do not attempt to retrieve RecordType information remotely but from this parameter + instead. multiple_choice : list[str], optional A list of reference Property names which shall be denoted as multiple choice properties. This means that each option in this property may be selected at most once. This is not @@ -118,6 +125,7 @@ class JsonSchemaExporter: self._do_not_create = do_not_create self._do_not_retrieve = do_not_retrieve self._no_remote = no_remote + self._use_rt_pool = use_rt_pool self._multiple_choice = multiple_choice self._wrap_files_in_objects = wrap_files_in_objects @@ -256,7 +264,9 @@ class JsonSchemaExporter: # Only a simple list of values json_prop["enum"] = values else: - if self._no_remote: + if self._use_rt_pool: + rt = self._use_rt_pool.get_deep(prop_name) + elif self._no_remote: rt = prop.datatype else: rt = db.execute_query(f"FIND RECORDTYPE WITH name='{prop_name}'", @@ -479,6 +489,7 @@ def recordtype_to_json_schema(rt: db.RecordType, additional_properties: bool = T do_not_create: List[str] = None, do_not_retrieve: List[str] = None, no_remote: bool = False, + use_rt_pool: DataModel = None, multiple_choice: List[str] = None, rjsf: bool = False, wrap_files_in_objects: bool = False @@ -524,6 +535,9 @@ def recordtype_to_json_schema(rt: db.RecordType, additional_properties: bool = T parameter, the behavior is undefined. no_remote : bool, optional If True, do not attempt to connect to a LinkAhead server at all. Default is False. + use_rt_pool : DataModel, optional + If given, do not attempt to retrieve RecordType information remotely but from this parameter + instead. multiple_choice : list[str], optional A list of reference Property names which shall be denoted as multiple choice properties. This means that each option in this property may be selected at most once. This is not @@ -560,6 +574,7 @@ def recordtype_to_json_schema(rt: db.RecordType, additional_properties: bool = T do_not_create=do_not_create, do_not_retrieve=do_not_retrieve, no_remote=no_remote, + use_rt_pool=use_rt_pool, multiple_choice=multiple_choice, wrap_files_in_objects=wrap_files_in_objects ) -- GitLab