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
013e4fdc
Commit
013e4fdc
authored
1 year ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
MAINT: Move RT treatment to separate function
parent
54aab5dd
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
+50
-23
50 additions, 23 deletions
src/caosadvancedtools/json_schema_exporter.py
with
50 additions
and
23 deletions
src/caosadvancedtools/json_schema_exporter.py
+
50
−
23
View file @
013e4fdc
...
...
@@ -120,6 +120,53 @@ def _make_text_property(description="", text_format=None, text_pattern=None):
return
prop
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
:
vals
.
append
(
f
"
{
val
.
id
}
"
)
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
):
schema
=
{
"
type
"
:
"
object
"
}
schema
[
"
required
"
]
=
_make_required_list
(
rt
)
schema
[
"
additionalProperties
"
]
=
additional_properties
props
=
{}
if
name_and_description_in_properties
:
props
[
"
name
"
]
=
_make_text_property
(
"
The name of the Record to be created
"
)
props
[
"
description
"
]
=
_make_text_property
(
"
The description of the Record to be created
"
)
for
prop
in
rt
.
properties
:
if
prop
.
name
in
props
:
# Multi property
raise
NotImplementedError
(
"
Creating a schema for multi-properties is not specified.
"
f
"
Property
{
prop
.
name
}
occurs more than once.
"
)
props
[
prop
.
name
]
=
_make_prop_from_prop
(
prop
,
additional_options_for_text_props
,
units_in_description
)
schema
[
"
properties
"
]
=
props
return
schema
def
recordtype_to_json_schema
(
rt
:
db
.
RecordType
,
additional_properties
:
bool
=
True
,
name_and_description_in_properties
:
bool
=
False
,
additional_options_for_text_props
:
Optional
[
dict
]
=
None
,
...
...
@@ -156,32 +203,12 @@ 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
=
{
"
$schema
"
:
"
https://json-schema.org/draft/2019-09/schema
"
,
"
type
"
:
"
object
"
}
schema
=
_treat_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
if
rt
.
description
:
schema
[
"
description
"
]
=
rt
.
description
schema
[
"
required
"
]
=
_make_required_list
(
rt
)
schema
[
"
additionalProperties
"
]
=
additional_properties
props
=
{}
if
name_and_description_in_properties
:
props
[
"
name
"
]
=
_make_text_property
(
"
The name of the Record to be created
"
)
props
[
"
description
"
]
=
_make_text_property
(
"
The description of the Record to be created
"
)
for
prop
in
rt
.
properties
:
if
prop
.
name
in
props
:
# Multi property
raise
NotImplementedError
(
"
Creating a schema for multi-properties is not specified.
"
f
"
Property
{
prop
.
name
}
occurs more than once.
"
)
props
[
prop
.
name
]
=
_make_prop_from_prop
(
prop
,
additional_options_for_text_props
,
units_in_description
)
schema
[
"
properties
"
]
=
props
return
schema
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