-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgen_jsondata.py
42 lines (38 loc) · 908 Bytes
/
gen_jsondata.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
#!/usr/bin/env python
# coding=utf-8
import sys
from apitools.datagenerator import DataGenerator
from jsonschema import validate
from jsonschema.exceptions import ValidationError
generator = DataGenerator()
user_schema = {
"type": "object",
"properties": {
"cellphone": {
"type": "string",
"pattern": "^[01]{3}-[0-9]{4}-[0-9]{4}$"
},
"age": {
"type": "integer",
"required": True,
"minimum": 0,
"maximum": 150
},
"name": {
"type": "string",
"required": True
},
"address": {
"type": "string",
"maxLength": 50
}
}
}
while True:
r = generator.random_value(user_schema)
try:
validate(r, user_schema)
break
except ValidationError as ve:
sys.stderr.write(str(ve) + "\n")
print(r)