-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.py
72 lines (66 loc) · 1.75 KB
/
example.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
from pprint import pprint
import jsonschema
import freddy
family_schema = {
"type": "array",
"minItems": 1,
"maxItems": 5,
"items": {
"properties": {
"member": {"$ref": "#/definitions/person"},
"role": {"$ref": "#/definitions/role"},
},
"type": "object",
},
"definitions": {
"person": {
"properties": {
"age": {"type": "integer"},
"name": {"type": "string"},
"pets": {
"items": {"$ref": "#/definitions/pet"},
"maxItems": 2,
"type": "array",
},
},
"type": "object",
},
"pet": {
"properties": {
"kind": {"enum": ["dog", "cat"], "type": "string"},
"name": {"type": "string"},
},
"type": "object",
},
"role": {
"enum": [
"father",
"mather",
"son",
"daughter",
"aunt",
"grandma",
"grandpa",
],
"type": "string",
},
}
}
# Get 10 random samples
for i in range(10):
sample_family = freddy.jsonschema(family_schema)
# Validate against schema
jsonschema.validate(sample_family, family_schema)
pprint(sample_family)
[
{"member": {"age": 77, "name": "k", "pets": []}, "role": "grandma"},
{"member": {"age": 64, "name": "naifvxf", "pets": []}, "role": "grandpa"},
{
"member": {
"age": 23,
"name": "itruydotrj",
"pets": [{"kind": "cat", "name": "o"}, {"kind": "cat", "name": "uonmvfgd"}],
},
"role": "son",
},
]