Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
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
RadioObservatory
LOFAR
Commits
09629bc9
Commit
09629bc9
authored
3 years ago
by
Jorrit Schaap
Browse files
Options
Downloads
Patches
Plain Diff
TMSS-860
: check if doc. equals schema. when validating
parent
a5d2c68d
No related branches found
No related tags found
1 merge request
!828
TMSS-860
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
LCS/PyCommon/json_utils.py
+6
-0
6 additions, 0 deletions
LCS/PyCommon/json_utils.py
SAS/TMSS/backend/src/tmss/tmssapp/models/common.py
+4
-4
4 additions, 4 deletions
SAS/TMSS/backend/src/tmss/tmssapp/models/common.py
with
10 additions
and
4 deletions
LCS/PyCommon/json_utils.py
+
6
−
0
View file @
09629bc9
...
@@ -488,6 +488,12 @@ def validate_json_object_with_schema(json_object, schema, add_defaults: bool=Fal
...
@@ -488,6 +488,12 @@ def validate_json_object_with_schema(json_object, schema, add_defaults: bool=Fal
"""
"""
Validate the given json_object with schema
Validate the given json_object with schema
"""
"""
if
'
$schema
'
in
json_object
and
'
$id
'
in
schema
:
object_schema_id
=
json_object
[
'
$schema
'
].
partition
(
'
#
'
)[
0
].
rstrip
(
'
/
'
).
rstrip
(
'
ref_resolved
'
).
rstrip
(
'
/
'
)
schema_id
=
schema
[
'
$id
'
].
partition
(
'
#
'
)[
0
].
rstrip
(
'
/
'
).
rstrip
(
'
ref_resolved
'
).
rstrip
(
'
/
'
)
if
object_schema_id
!=
schema_id
:
raise
JSONError
(
"
json_object refers to different $schema=
'
%s
'
and cannot be compared to the schema with $id=
'
%s
'"
%
(
object_schema_id
,
schema_id
))
get_validator_for_schema
(
schema
,
add_defaults
=
add_defaults
).
validate
(
json_object
)
get_validator_for_schema
(
schema
,
add_defaults
=
add_defaults
).
validate
(
json_object
)
return
json_object
return
json_object
...
...
This diff is collapsed.
Click to expand it.
SAS/TMSS/backend/src/tmss/tmssapp/models/common.py
+
4
−
4
View file @
09629bc9
...
@@ -260,10 +260,10 @@ class AbstractSchemaTemplate(AbstractTemplate):
...
@@ -260,10 +260,10 @@ class AbstractSchemaTemplate(AbstractTemplate):
# this template's schema has a schema of its own (usually the draft-06 meta schema). Validate it.
# this template's schema has a schema of its own (usually the draft-06 meta schema). Validate it.
validate_json_against_its_schema
(
self
.
schema
,
cache
=
TemplateSchemaMixin
.
_schema_cache
,
max_cache_age
=
TemplateSchemaMixin
.
_MAX_SCHEMA_CACHE_AGE
)
validate_json_against_its_schema
(
self
.
schema
,
cache
=
TemplateSchemaMixin
.
_schema_cache
,
max_cache_age
=
TemplateSchemaMixin
.
_MAX_SCHEMA_CACHE_AGE
)
def
validate_document
(
self
,
json_doc
:
typing
.
Union
[
str
,
dict
])
->
bool
:
def
validate_document
_against_schema
(
self
,
json_doc
:
typing
.
Union
[
str
,
dict
]):
'''
validate the given json_doc against th
e
template
'
s schema
'''
validate the given json_doc against th
is
template
'
s schema
If no exception if thrown, then the given json_
string
validates
against the given schema
.
If no exception if thrown, then the given json_
doc
validates.
:raises SchemaValidationException if the json_
string
does not validate against th
e
schema
'''
:raises SchemaValidationException if the json_
doc
does not validate against th
is template
'
s
schema
'''
validate_json_against_schema
(
json_doc
,
self
.
schema
,
cache
=
TemplateSchemaMixin
.
_schema_cache
,
max_cache_age
=
TemplateSchemaMixin
.
_MAX_SCHEMA_CACHE_AGE
)
validate_json_against_schema
(
json_doc
,
self
.
schema
,
cache
=
TemplateSchemaMixin
.
_schema_cache
,
max_cache_age
=
TemplateSchemaMixin
.
_MAX_SCHEMA_CACHE_AGE
)
@property
@property
...
...
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