-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathexample_python.py
98 lines (88 loc) · 3.24 KB
/
example_python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from jsonschemacodegen import python as pygen
import json
if __name__ == '__main__':
schema = {
"type": "array",
"items": {
"oneOf": [
{
"type": "string",
"title": "StringOption",
},
{
"type": "integer",
"title": "InterGerOption",
},
{
"type": "object",
"title": "an object",
"properties": {
"astring": {"type": "string"},
"aboolean": {"type": "boolean"},
},
"required": [
"aboolean"
]
},
{
"allOf": [
{
"type": "object",
"properties": {
"banana": {"type": "string"},
},
"required": ["banana"],
},
{
"type": "object",
"properties": {
"apple": {"type": "string"},
},
"required": ["apple"]
}
]
},
{
"type": "null"
}
]
}
}
if True:
generator = pygen.GeneratorFromSchema('output')
generator.Generate(schema, 'Example', 'example')
with open('output/__init__.py', 'w') as fp:
pass
from output import example
def JsonPrint(o):
print(json.dumps(o, default=lambda x: x.Serializable()))
data = [
"a",
1,
{"astring": "bool is true", "aboolean": True},
{"astring": "bool is false", "aboolean": False},
{"banana": "yello", "apple": "red"},
None,
]
#exampleObj = example.Example(data)
#assert(exampleObj[3].Get().GetAstring().Get() == data[3]['astring'])
#assert(exampleObj[3].Get().GetAboolean().Get() == False)
#JsonPrint(exampleObj)
#f = example.Example()
#JsonPrint(f)
#nullObj1 = example.Example.Item.Option5()
#nullObj2 = example.Example.Item.Option5(None)
#nullObj3 = example.Example.Item.Option5(nullObj1)
#g = example.Example.Item(nullObj3)
#JsonPrint(g)
#comboObject1 = example.Example.Item.Option4({"apple": "a", "banana": "b"})
#comboObject2 = example.Example.Item.Option4(comboObject1)
#comboObject3 = example.Example.Item.Option4({"apple":"ap"}, {"banana", "ba"})
#comboObject4Comp1 = example.Example.Item.Option4.Component1(apple="ap")
#comboObject3 = example.Example.Item.Option4(comboObject4Comp1, {"banana", "ba"})
#h = example.Example.Item(comboObject2)
#JsonPrint(h)
JsonPrint(example.Example.Item({"banana": "yello", "apple": "red"}))
#objectThree1 = example.Example.Item.AnObjectOption(astring="jacob", aboolean=True)
#objectThree2 = example.Example.Item.AnObjectOption({"astring":"jacob", "aboolean":True})
#objectThree3 = example.Example.Item.AnObjectOption(objectThree1)