oarepo-runtime 1.5.65__py3-none-any.whl → 1.5.67__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
+ }