Skip to content
Snippets Groups Projects
Commit 2e459d6a authored by florian's avatar florian
Browse files

ENH: Also treat atomic-type patternProperties

parent 2f24e638
No related branches found
No related tags found
2 merge requests!73MAINT: change wording of TableImporter argument and allow converters and...,!72Extend json-schema model parser
Pipeline #36819 failed
......@@ -876,7 +876,16 @@ class JsonSchemaParser(Parser):
def _treat_pattern_properties(self, pattern_elements, name_prefix=""):
"""Special Treatment for pattern properties: A RecordType is created for
each pattern property.
each pattern property. In case of a `type: object` PatternProperty, the
remaining properties of the JSON entry are appended to the new
RecordType; in case of an atomic type PatternProperty, a single value
Property is added to the RecordType.
Raises
------
NotImplementedError
In case of patternProperties with non-object, non-atomic type, e.g.,
array.
"""
num_patterns = len(pattern_elements)
......@@ -884,17 +893,32 @@ class JsonSchemaParser(Parser):
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)
name = name_prefix + "Entry" + name_suffix
if element["type"] == "object":
# simple, is already an object, so can be treated like any other
# record type.
pattern_type = self._treat_record_type(element, name)
elif element["type"] in JSON_SCHEMA_ATOMIC_TYPES:
# create a property that stores the actual value of the pattern
# property.
propname = f"{name}_value"
prop = db.Property(name=propname, datatype=self._get_atomic_datatype(element))
self.model[propname] = prop
pattern_type = db.RecordType(name=name)
pattern_type.add_property(prop)
else:
raise NotImplementedError(
"Pattern properties are currently only supported for types " +
", ".join(JSON_SCHEMA_ATOMIC_TYPES) + ", and object.")
# Add pattern property and description
pattern_type.add_property(pattern_prop)
pattern_type.add_property(pattern_prop, importance=db.OBLIGATORY)
if pattern_type.description:
pattern_type.description += f"\n\npattern: {key}"
else:
pattern_type.description = f"pattern: {key}"
model[name] = pattern_type
self.model[name] = pattern_type
returns.append(pattern_type)
return returns
......
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