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
797817e0
Verified
Commit
797817e0
authored
1 year ago
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
MAINT: Renamed a few functions.
parent
a4e990c8
No related branches found
No related tags found
2 merge requests
!89
ENH: JsonSchemaExporter accepts do_not_create parameter.
,
!81
F schema export references
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+1
-1
1 addition, 1 deletion
CHANGELOG.md
README_SETUP.md
+2
-1
2 additions, 1 deletion
README_SETUP.md
src/caosadvancedtools/json_schema_exporter.py
+21
-19
21 additions, 19 deletions
src/caosadvancedtools/json_schema_exporter.py
with
24 additions
and
21 deletions
CHANGELOG.md
+
1
−
1
View file @
797817e0
...
...
@@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
*
Parsing from YAML now allows to give an existing model to which the YAML data model shall be
added.
*
The
`json_schema_exporter`
module which introduces tools to create a json
schema from a RecordType, e.g., for the us
e
age in web forms.
schema from a RecordType, e.g., for the usage in web forms.
### Changed ###
...
...
This diff is collapsed.
Click to expand it.
README_SETUP.md
+
2
−
1
View file @
797817e0
...
...
@@ -34,7 +34,8 @@ Optional h5-crawler:
## Run Unit Tests
-
All tests:
`tox`
-
One specific test:
`tox -- -k expression`
-
One specific test with tox:
`tox -- unittests/test_myusecase.py -k expression`
-
Or even using only pytest:
`pytest unittests/test_myusecase.py -k expression`
## Run Integration Tests Locally
...
...
This diff is collapsed.
Click to expand it.
src/caosadvancedtools/json_schema_exporter.py
+
21
−
19
View file @
797817e0
...
...
@@ -33,10 +33,10 @@ def _make_required_list(rt: db.RecordType):
if
rt
.
get_importance
(
prop
.
name
)
==
db
.
OBLIGATORY
]
def
_make_
prop
_from_prop
(
prop
:
db
.
Property
,
additional_properties
:
bool
,
name_and_description_in_properties
:
bool
,
additional_options_for_text_props
:
Optional
[
dict
],
units_in_description
:
bool
):
def
_make_
segment
_from_prop
(
prop
:
db
.
Property
,
additional_properties
:
bool
,
name_and_description_in_properties
:
bool
,
additional_options_for_text_props
:
Optional
[
dict
],
units_in_description
:
bool
):
"""
Return the JSON Schema segment for the given property
Parameters
...
...
@@ -44,7 +44,7 @@ def _make_prop_from_prop(prop: db.Property, additional_properties: bool,
prop : db.Property
the property to be transformed
additional_properties : bool, optional
Whether additional propeties will be admitted in the resulting
Whether additional prope
r
ties will be admitted in the resulting
schema. Optional, default is True.
name_and_description_in_properties : bool, optional
Whether to include name and description in the `properties` section of
...
...
@@ -99,7 +99,7 @@ def _make_prop_from_prop(prop: db.Property, additional_properties: bool,
json_prop
[
"
type
"
]
=
"
array
"
list_element_prop
=
db
.
Property
(
name
=
prop
.
name
,
datatype
=
get_list_datatype
(
prop
.
datatype
,
strict
=
True
))
json_prop
[
"
items
"
]
=
_make_
prop
_from_prop
(
json_prop
[
"
items
"
]
=
_make_
segment
_from_prop
(
list_element_prop
,
additional_properties
,
name_and_description_in_properties
,
additional_options_for_text_props
,
units_in_description
...
...
@@ -116,10 +116,10 @@ def _make_prop_from_prop(prop: db.Property, additional_properties: bool,
else
:
values
=
_retrieve_enum_values
(
f
"
RECORD
'
{
prop
.
datatype
}
'"
)
rt
=
db
.
execute_query
(
f
"
FIND RECORDTYPE WITH name=
'
{
prop
.
datatype
}
'"
,
unique
=
True
)
subschema
=
_
treat
_recordtype
(
rt
,
additional_properties
,
name_and_description_in_properties
,
additional_options_for_text_props
,
units_in_description
)
subschema
=
_
make_segment_from
_recordtype
(
rt
,
additional_properties
,
name_and_description_in_properties
,
additional_options_for_text_props
,
units_in_description
)
json_prop
[
"
oneOf
"
]
=
[
{
"
enum
"
:
values
},
subschema
...
...
@@ -167,9 +167,7 @@ def _retrieve_enum_values(role: str):
possible_values
=
db
.
execute_query
(
f
"
SELECT name, id FROM
{
role
}
"
)
vals
=
[]
for
val
in
possible_values
:
if
val
.
name
:
vals
.
append
(
f
"
{
val
.
id
}
,
{
val
.
name
}
"
)
else
:
...
...
@@ -178,10 +176,12 @@ def _retrieve_enum_values(role: str):
return
vals
def
_treat_recordtype
(
rt
:
db
.
RecordType
,
additional_properties
:
bool
=
True
,
name_and_description_in_properties
:
bool
=
False
,
additional_options_for_text_props
:
Optional
[
dict
]
=
None
,
units_in_description
:
bool
=
True
):
def
_make_segment_from_recordtype
(
rt
:
db
.
RecordType
,
additional_properties
:
bool
=
True
,
name_and_description_in_properties
:
bool
=
False
,
additional_options_for_text_props
:
Optional
[
dict
]
=
None
,
units_in_description
:
bool
=
True
):
"""
Return a Json schema segment for the given RecordType.
"""
schema
=
{
"
type
"
:
"
object
"
}
...
...
@@ -201,7 +201,7 @@ def _treat_recordtype(rt: db.RecordType, additional_properties: bool = True,
"
Creating a schema for multi-properties is not specified.
"
f
"
Property
{
prop
.
name
}
occurs more than once.
"
)
props
[
prop
.
name
]
=
_make_
prop
_from_prop
(
props
[
prop
.
name
]
=
_make_
segment
_from_prop
(
prop
,
additional_properties
,
name_and_description_in_properties
,
additional_options_for_text_props
,
units_in_description
)
...
...
@@ -246,8 +246,10 @@ def recordtype_to_json_schema(rt: db.RecordType, additional_properties: bool = T
if
additional_options_for_text_props
is
None
:
additional_options_for_text_props
=
{}
schema
=
_treat_recordtype
(
rt
,
additional_properties
,
name_and_description_in_properties
,
additional_options_for_text_props
,
units_in_description
)
schema
=
_make_segment_from_recordtype
(
rt
,
additional_properties
,
name_and_description_in_properties
,
additional_options_for_text_props
,
units_in_description
)
schema
[
"
$schema
"
]
=
"
https://json-schema.org/draft/2019-09/schema
"
if
rt
.
name
:
schema
[
"
title
"
]
=
rt
.
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