From 4e665cd8e95538695c8091928b2363a68e423976 Mon Sep 17 00:00:00 2001 From: florian <f.spreckelsen@inidscale.com> Date: Mon, 15 May 2023 14:12:04 +0200 Subject: [PATCH] ENH: Treat pattern properties --- src/caosadvancedtools/models/parser.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/caosadvancedtools/models/parser.py b/src/caosadvancedtools/models/parser.py index fe315b02..6bfe494c 100644 --- a/src/caosadvancedtools/models/parser.py +++ b/src/caosadvancedtools/models/parser.py @@ -814,7 +814,7 @@ class JsonSchemaParser(Parser): if "patternProperties" in elt: - pattern_property_rts = self_treat_pattern_properties( + pattern_property_rts = self._treat_pattern_properties( elt["patternProperties"], name_prefix=name) for ppr in pattern_property_rts: # add reference to pattern property type. These can never be @@ -875,12 +875,29 @@ class JsonSchemaParser(Parser): return pp def _treat_pattern_properties(self, pattern_elements, name_prefix=""): - """Special Treatment for pattern properties: A RecordType is created for each pattern property.""" + """Special Treatment for pattern properties: A RecordType is created for + each pattern property. + + """ num_patterns = len(pattern_elements) pattern_prop = self._get_pattern_prop() + returns = [] for ii, (key, element) in enumerate(pattern_elements.items()): name_suffix = f"_{ii+1}" if num_patterns > 1 else "" name = name_prefix + "Element" + name_suffix + pattern_type = self._treat_record_type(element, name) + + # Add pattern property and description + pattern_type.add_property(pattern_prop) + if pattern_type.description: + pattern_type.description += f"\n\npattern: {key}" + else: + pattern_type.description = f"pattern: {key}" + + model[name] = pattern_type + returns.append(pattern_type) + + return returns if __name__ == "__main__": -- GitLab