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
d757f2b7
Verified
Commit
d757f2b7
authored
3 years ago
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
STY: Some style changes.
parent
9cc0ae43
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!39
Release 0.4.0
,
!33
F json schema datamodel
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pylintrc
+9
-0
9 additions, 0 deletions
pylintrc
pytest.ini
+0
-1
0 additions, 1 deletion
pytest.ini
src/caosadvancedtools/models/parser.py
+9
-9
9 additions, 9 deletions
src/caosadvancedtools/models/parser.py
with
18 additions
and
10 deletions
pylintrc
0 → 100644
+
9
−
0
View file @
d757f2b7
# -*- mode:conf; -*-
[
FORMAT
]
# Good variable names which should always be accepted, separated by a comma
good
-
names
=
ii
,
rt
[
TYPECHECK
]
ignored
-
modules
=
etree
This diff is collapsed.
Click to expand it.
pytest.ini
+
0
−
1
View file @
d757f2b7
[pytest]
testpaths
=
unittests
addopts
=
-vv
python_paths
=
src
This diff is collapsed.
Click to expand it.
src/caosadvancedtools/models/parser.py
+
9
−
9
View file @
d757f2b7
...
...
@@ -99,6 +99,7 @@ class YamlDefinitionError(RuntimeError):
class
JsonSchemaDefinitionError
(
RuntimeError
):
# @author Florian Spreckelsen
# @date 2022-02-17
# @review Daniel Hornung 2022-02-18
def
__init__
(
self
,
msg
):
super
().
__init__
(
msg
)
...
...
@@ -121,6 +122,7 @@ def parse_model_from_json_schema(filename: str):
"""
Return a datamodel parsed from a json schema definition.
"""
# @author Florian Spreckelsen
# @date 2022-02-17
# @review Daniel Hornung 2022-02-18
parser
=
JsonSchemaParser
()
return
parser
.
parse_model_from_json_schema
(
filename
)
...
...
@@ -466,6 +468,7 @@ class JsonSchemaParser(Parser):
"""
Extends the yaml parser to read in datamodels defined in a json schema.
"""
# @author Florian Spreckelsen
# @date 2022-02-17
# @review Daniel Hornung 2022-02-18
def
parse_model_from_json_schema
(
self
,
filename
:
str
):
"""
Return a datamodel created from the definition in the json schema in
...
...
@@ -506,12 +509,10 @@ class JsonSchemaParser(Parser):
model_dict
=
[
model_dict
]
for
ii
,
elt
in
enumerate
(
model_dict
):
if
not
"
title
"
in
elt
:
raise
JsonSchemaDefinitionError
(
"
Object {} is lacking the `title` key word
"
.
format
(
ii
+
1
))
if
not
"
type
"
in
elt
:
raise
JsonSchemaDefinitionError
(
"
Object {} is lacking the `type` key word
"
.
format
(
ii
+
1
))
if
"
title
"
not
in
elt
:
raise
JsonSchemaDefinitionError
(
f
"
Object
{
ii
+
1
}
is lacking the `title` key word
"
)
if
"
type
"
not
in
elt
:
raise
JsonSchemaDefinitionError
(
f
"
Object
{
ii
+
1
}
is lacking the `type` key word
"
)
name
=
self
.
_stringify
(
elt
[
"
title
"
],
context
=
elt
)
self
.
_treat_element
(
elt
,
name
)
...
...
@@ -535,8 +536,7 @@ class JsonSchemaParser(Parser):
elif
elt
[
"
type
"
]
==
"
object
"
:
ent
=
self
.
_treat_record_type
(
elt
,
name
)
else
:
raise
NotImplementedError
(
"
Cannot parse items of type
'
{}
'
(yet).
"
.
format
(
elt
[
"
type
"
]))
raise
NotImplementedError
(
f
"
Cannot parse items of type
'
{
elt
[
'
type
'
]
}
'
(yet).
"
)
if
"
description
"
in
elt
:
ent
.
description
=
elt
[
"
description
"
]
...
...
@@ -552,7 +552,7 @@ class JsonSchemaParser(Parser):
if
"
properties
"
in
elt
:
for
key
,
prop
in
elt
[
"
properties
"
].
items
():
if
"
title
"
in
prop
:
name
=
self
.
_stringify
(
title
)
name
=
self
.
_stringify
(
prop
[
"
title
"
]
)
else
:
name
=
self
.
_stringify
(
key
)
prop_ent
=
self
.
_treat_element
(
prop
,
name
)
...
...
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