oarepo-runtime 1.5.66__py3-none-any.whl → 1.5.68__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- oarepo_runtime/info/check.py +0 -1
- oarepo_runtime/info/views.py +16 -4
- oarepo_runtime/resources/json_serializer.py +27 -0
- oarepo_runtime/services/schema/marshmallow_to_json_schema.py +72 -0
- {oarepo_runtime-1.5.66.dist-info → oarepo_runtime-1.5.68.dist-info}/METADATA +1 -1
- {oarepo_runtime-1.5.66.dist-info → oarepo_runtime-1.5.68.dist-info}/RECORD +13 -8
- tests/marshmallow_to_json/__init__.py +0 -0
- tests/marshmallow_to_json/test_datacite_ui_schema.py +1410 -0
- tests/marshmallow_to_json/test_simple_schema.py +52 -0
- {oarepo_runtime-1.5.66.dist-info → oarepo_runtime-1.5.68.dist-info}/LICENSE +0 -0
- {oarepo_runtime-1.5.66.dist-info → oarepo_runtime-1.5.68.dist-info}/WHEEL +0 -0
- {oarepo_runtime-1.5.66.dist-info → oarepo_runtime-1.5.68.dist-info}/entry_points.txt +0 -0
- {oarepo_runtime-1.5.66.dist-info → oarepo_runtime-1.5.68.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
from marshmallow import Schema, fields
|
2
|
+
from oarepo_runtime.services.schema.marshmallow_to_json_schema import marshmallow_to_json_schema
|
3
|
+
|
4
|
+
class SimpleSchema(Schema):
|
5
|
+
a = fields.Integer()
|
6
|
+
b = fields.String()
|
7
|
+
|
8
|
+
def test_simple_schema():
|
9
|
+
schema = SimpleSchema()
|
10
|
+
converted = marshmallow_to_json_schema(schema)
|
11
|
+
|
12
|
+
assert converted == {
|
13
|
+
"type": "object",
|
14
|
+
"properties": {
|
15
|
+
"a": {"type": "integer"},
|
16
|
+
"b": {"type": "string"}
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
class AddressSchema(Schema):
|
21
|
+
city = fields.String()
|
22
|
+
postal_code = fields.String()
|
23
|
+
|
24
|
+
class MoreComplexSchema(Schema):
|
25
|
+
name = fields.String(required=True)
|
26
|
+
age = fields.Integer()
|
27
|
+
score = fields.Float()
|
28
|
+
is_active = fields.Boolean()
|
29
|
+
tags = fields.List(fields.String())
|
30
|
+
address = fields.Nested(lambda: AddressSchema)
|
31
|
+
|
32
|
+
def test_more_complex_schema():
|
33
|
+
schema = MoreComplexSchema()
|
34
|
+
converted = marshmallow_to_json_schema(schema)
|
35
|
+
|
36
|
+
assert converted == {
|
37
|
+
"type": "object",
|
38
|
+
"properties": {
|
39
|
+
'name': {'type': 'string'},
|
40
|
+
'age': {'type': 'integer'},
|
41
|
+
'score': {'type': 'number'},
|
42
|
+
'is_active': {'type': 'boolean'},
|
43
|
+
'tags': {'type': 'array', 'items': {'type': 'string'}},
|
44
|
+
'address': {
|
45
|
+
'type': 'object',
|
46
|
+
"properties": {
|
47
|
+
'city': {'type': 'string'},
|
48
|
+
'postal_code': {'type': 'string'}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|