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
15811aba
Commit
15811aba
authored
1 year ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Implement reference properties
parent
013e4fdc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!89
ENH: JsonSchemaExporter accepts do_not_create parameter.
,
!81
F schema export references
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosadvancedtools/json_schema_exporter.py
+38
-9
38 additions, 9 deletions
src/caosadvancedtools/json_schema_exporter.py
with
38 additions
and
9 deletions
src/caosadvancedtools/json_schema_exporter.py
+
38
−
9
View file @
15811aba
...
...
@@ -33,13 +33,22 @@ def _make_required_list(rt: db.RecordType):
if
rt
.
get_importance
(
prop
.
name
)
==
db
.
OBLIGATORY
]
def
_make_prop_from_prop
(
prop
:
db
.
Property
,
additional_options_for_text_props
:
Optional
[
dict
],
units_in_description
:
bool
):
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
):
"""
Return the JSON Schema segment for the given property
Parameters
----------
prop : db.Property
the property to be transformed
additional_properties : bool, optional
Whether additional propeties 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
the schema to be exported. Optional, default is False.
additional_options_for_text_props : Optional[dict]
dict of dicts that may contain the keys
'
pattern
'
and
'
format
'
to
further define the rules for the JSON Schema segment
...
...
@@ -49,11 +58,6 @@ def _make_prop_from_prop(prop: db.Property, additional_options_for_text_props: O
instead.
"""
if
prop
.
is_reference
():
raise
NotImplementedError
(
"
Reference properties are not supported in this version of the json schema exporter.
"
)
if
prop
.
datatype
==
db
.
TEXT
or
prop
.
datatype
==
db
.
DATETIME
:
text_format
=
None
text_pattern
=
None
...
...
@@ -94,7 +98,31 @@ def _make_prop_from_prop(prop: db.Property, additional_options_for_text_props: O
list_element_prop
=
db
.
Property
(
name
=
prop
.
name
,
datatype
=
get_list_datatype
(
prop
.
datatype
,
strict
=
True
))
json_prop
[
"
items
"
]
=
_make_prop_from_prop
(
list_element_prop
,
additional_options_for_text_props
,
units_in_description
)
list_element_prop
,
additional_properties
,
name_and_description_in_properties
,
additional_options_for_text_props
,
units_in_description
)
elif
prop
.
is_reference
():
if
prop
.
datatype
==
db
.
REFERENCE
:
# No Record creation since no RT is specified and we don't know what
# schema to use, so only enum of all Records and all Files.
values
=
_retrieve_enum_values
(
"
RECORD
"
)
+
_retrieve_enum_values
(
"
FILE
"
)
json_prop
[
"
enum
"
]
=
values
elif
prop
.
datatype
==
db
.
FILE
:
# TODO: different issue
raise
NotImplementedError
(
"
Files have not been implemented yet.
"
)
else
:
values
=
_retrieve_enum_values
(
f
"
RECORD
'
{
prop
.
datatype
}
'"
)
rt
=
db
.
execute_query
(
f
"
FIND RECORDTYPE
'
{
prop
.
datatype
}
'"
,
unique
=
True
)
subschema
=
_treat_recordtype
(
rt
,
additional_properties
,
name_and_description_in_properties
,
additional_options_for_text_props
,
units_in_description
)
json_prop
[
"
oneOf
"
]
=
[
{
"
enum
"
:
values
},
subschema
]
else
:
raise
ValueError
(
f
"
Unknown or no property datatype. Property
{
prop
.
name
}
with type
{
prop
.
datatype
}
"
)
...
...
@@ -122,7 +150,7 @@ def _make_text_property(description="", text_format=None, text_pattern=None):
def
_retrieve_enum_values
(
role
:
str
):
possible_values
=
db
.
execute_query
(
f
"
SELECT name, id FROM
'
{
role
}
'
"
)
possible_values
=
db
.
execute_query
(
f
"
SELECT name, id FROM
{
role
}
"
)
vals
=
[]
...
...
@@ -160,7 +188,8 @@ def _treat_recordtype(rt: db.RecordType, additional_properties: bool = True,
f
"
Property
{
prop
.
name
}
occurs more than once.
"
)
props
[
prop
.
name
]
=
_make_prop_from_prop
(
prop
,
additional_options_for_text_props
,
units_in_description
)
prop
,
additional_properties
,
name_and_description_in_properties
,
additional_options_for_text_props
,
units_in_description
)
schema
[
"
properties
"
]
=
props
...
...
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