Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CaosDB Crawler
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 Crawler
Commits
ae694da6
Commit
ae694da6
authored
5 months ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
FIX(validator): patches are applied recursively to match substructure of records
parent
5f84d8fd
No related branches found
No related tags found
2 merge requests
!217
TST: Make NamedTemporaryFiles Windows-compatible
,
!201
Validator that checks created records using a json schema
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caoscrawler/validator.py
+25
-13
25 additions, 13 deletions
src/caoscrawler/validator.py
with
25 additions
and
13 deletions
src/caoscrawler/validator.py
+
25
−
13
View file @
ae694da6
...
...
@@ -71,25 +71,20 @@ def representer_ordereddict(dumper, data):
return
dumper
.
represent_data
(
dict
(
data
))
def
convert_record
(
record
:
db
.
Record
):
def
apply_schema_patches
(
pobj
:
dict
):
"""
Convert a record into a form suitable for validation with jsonschema.
Uses high_level_api.convert_to_python_object
Changes applied:
- properties are moved vom subitem
"
proeprties
"
to top-level.
- The following keys are deleted: parents, role, name, description, metadata, properties
Arguments:
----------
record: db.Record
The record that is supposed to be converted.
"""
pobj
=
convert_to_python_object
(
record
).
serialize
()
if
"
properties
"
not
in
pobj
:
# this is probably a file
return
pobj
for
prop
in
pobj
[
"
properties
"
]:
pobj
[
prop
]
=
pobj
[
"
properties
"
][
prop
]
if
isinstance
(
pobj
[
"
properties
"
][
prop
],
dict
):
pobj
[
prop
]
=
apply_schema_patches
(
pobj
[
"
properties
"
][
prop
])
else
:
pobj
[
prop
]
=
pobj
[
"
properties
"
][
prop
]
for
keyd
in
(
"
parents
"
,
"
role
"
,
"
name
"
,
"
description
"
,
"
metadata
"
,
"
properties
"
):
...
...
@@ -99,6 +94,23 @@ def convert_record(record: db.Record):
return
pobj
def
convert_record
(
record
:
db
.
Record
):
"""
Convert a record into a form suitable for validation with jsonschema.
Uses high_level_api.convert_to_python_object
Afterwards apply_schema_patches is called recursively to refactor the dictionary
to match the current form of the jsonschema.
Arguments:
----------
record: db.Record
The record that is supposed to be converted.
"""
pobj
=
convert_to_python_object
(
record
).
serialize
()
return
apply_schema_patches
(
pobj
)
def
validate
(
records
:
list
[
db
.
Record
],
schemas
:
list
[
dict
])
->
list
[
tuple
[
bool
,
list
]]:
"""
Validate a list of records against a list of possible JSON schemas.
...
...
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