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
f00c3de9
Verified
Commit
f00c3de9
authored
1 year ago
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
FIX: datetime has "string" type in options now
parent
10f293f5
No related branches found
No related tags found
2 merge requests
!89
ENH: JsonSchemaExporter accepts do_not_create parameter.
,
!80
F simple schema export
Pipeline
#42817
failed
1 year ago
Stage: setup
Stage: cert
Stage: style
Stage: unittest
Stage: integrationtest
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caosadvancedtools/json_schema_exporter.py
+17
-2
17 additions, 2 deletions
src/caosadvancedtools/json_schema_exporter.py
unittests/test_json_schema_exporter.py
+12
-4
12 additions, 4 deletions
unittests/test_json_schema_exporter.py
with
29 additions
and
6 deletions
src/caosadvancedtools/json_schema_exporter.py
+
17
−
2
View file @
f00c3de9
...
...
@@ -33,7 +33,8 @@ 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_options_for_text_props
:
Optional
[
dict
],
units_in_description
:
bool
):
"""
Return the JSON Schema segment for the given property
Parameters
...
...
@@ -54,6 +55,8 @@ def _make_prop_from_prop(prop: db.Property, additional_options_for_text_props: O
"
Reference properties are not supported in this version of the json schema exporter.
"
)
if
not
additional_options_for_text_props
:
additional_options_for_text_props
=
{}
if
prop
.
datatype
==
db
.
TEXT
or
prop
.
datatype
==
db
.
DATETIME
:
text_format
=
None
text_pattern
=
None
...
...
@@ -111,7 +114,19 @@ def _make_text_property(description="", text_format=None, text_pattern=None):
prop
[
"
description
"
]
=
description
if
text_format
is
not
None
:
if
isinstance
(
text_format
,
list
):
prop
[
"
anyOf
"
]
=
[{
"
format
"
:
tf
}
for
tf
in
text_format
]
# We want the type inside the options, not in the head:
# "datetime property": {
# "anyOf": [
# {
# "type": "string",
# "format": "date"
# },
# {
# "type": "string",
# "format": "date-time"
# }]}
prop
.
pop
(
"
type
"
)
prop
[
"
anyOf
"
]
=
[{
"
type
"
:
"
string
"
,
"
format
"
:
tf
}
for
tf
in
text_format
]
else
:
prop
[
"
format
"
]
=
text_format
if
text_pattern
is
not
None
:
...
...
This diff is collapsed.
Click to expand it.
unittests/test_json_schema_exporter.py
+
12
−
4
View file @
f00c3de9
...
...
@@ -85,12 +85,20 @@ def test_rt_with_scalar_props():
assert
props
[
"
SimpleText
"
][
"
description
"
]
==
"
This is a simple text
"
assert
"
ObligatoryDatetime
"
in
props
assert
props
[
"
ObligatoryDatetime
"
]
[
"
type
"
]
==
"
string
"
assert
"
type
"
not
in
props
[
"
ObligatoryDatetime
"
]
assert
"
anyOf
"
in
props
[
"
ObligatoryDatetime
"
]
assert
len
(
props
[
"
ObligatoryDatetime
"
][
"
anyOf
"
])
==
2
fmts
=
[
fmt
[
"
format
"
]
for
fmt
in
props
[
"
ObligatoryDatetime
"
][
"
anyOf
"
]]
assert
"
date
"
in
fmts
assert
"
date-time
"
in
fmts
date_found
=
0
datetime_found
=
0
for
option
in
props
[
"
ObligatoryDatetime
"
][
"
anyOf
"
]:
assert
option
[
"
type
"
]
==
"
string
"
fmt
=
option
[
"
format
"
]
if
fmt
==
"
date
"
:
date_found
+=
1
if
fmt
==
"
date-time
"
:
datetime_found
+=
1
assert
date_found
==
1
assert
datetime_found
==
1
assert
"
JustDateNoTime
"
in
props
assert
props
[
"
JustDateNoTime
"
][
"
type
"
]
==
"
string
"
...
...
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