Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uhepp.org
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Frank Sauerburger
uhepp.org
Merge requests
!13
Resolve "Validate data against json schema"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Validate data against json schema"
17-validate-data-against-json-schema
into
master
Overview
0
Commits
4
Pipelines
4
Changes
5
Merged
Frank Sauerburger
requested to merge
17-validate-data-against-json-schema
into
master
4 years ago
Overview
0
Commits
4
Pipelines
4
Changes
5
Expand
Closes
#17 (closed)
Edited
4 years ago
by
Frank Sauerburger
0
0
Merge request reports
Viewing commit
b44c6043
Prev
Next
Show latest version
5 files
+
303
−
5
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
Verified
b44c6043
Validate JSON schema
· b44c6043
Frank Sauerburger
authored
4 years ago
uhepp_org/uhepp_api/serializers.py
+
21
−
0
Options
import
json
import
os
from
django.contrib.auth.models
import
User
from
django.db.models
import
Q
from
django.urls
import
reverse
from
rest_framework
import
serializers
import
jsonschema
from
uhepp_vault.models
import
PUBLIC_LEVEL
,
INTERNAL_LEVEL
,
PUBLIC_LEVEL
,
\
VISIBILITY_LEVELS
,
Plot
,
Collection
from
.masks
import
filter_collections
@@ -70,6 +73,24 @@ class PlotSerializer(serializers.HyperlinkedModelSerializer):
'
collection-detail
'
,
queryset
=
Collection
.
objects
)
def
validate_uhepp
(
self
,
value
):
"""
Check if the JSON data conforms to the uhepp schema
"""
try
:
schema_path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"
uhepp.schema.json
"
)
with
open
(
schema_path
)
as
schema_file
:
schema
=
json
.
load
(
schema_file
)
jsonschema
.
validate
(
value
,
schema
=
schema
)
except
Exception
as
e
:
raise
serializers
.
ValidationError
(
"
JSON schema validation error: %s
"
%
e
)
return
value
class
Meta
:
model
=
Plot
fields
=
[
"
uuid
"
,
"
collection
"
,
"
url
"
,
"
uhepp
"
]
Loading