Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-advanced-user-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-advanced-user-tools
Commits
2e459d6a
Commit
2e459d6a
authored
1 year ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Also treat atomic-type patternProperties
parent
2f24e638
No related branches found
No related tags found
2 merge requests
!73
MAINT: change wording of TableImporter argument and allow converters and...
,
!72
Extend json-schema model parser
Pipeline
#36819
failed
1 year ago
Stage: setup
Stage: cert
Stage: style
Stage: unittest
Stage: integrationtest
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosadvancedtools/models/parser.py
+29
-5
29 additions, 5 deletions
src/caosadvancedtools/models/parser.py
with
29 additions
and
5 deletions
src/caosadvancedtools/models/parser.py
+
29
−
5
View file @
2e459d6a
...
...
@@ -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\n
pattern:
{
key
}
"
else
:
pattern_type
.
description
=
f
"
pattern:
{
key
}
"
model
[
name
]
=
pattern_type
self
.
model
[
name
]
=
pattern_type
returns
.
append
(
pattern_type
)
return
returns
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment