-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
34 lines (24 loc) · 849 Bytes
/
utils.py
File metadata and controls
34 lines (24 loc) · 849 Bytes
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
def generate_json_from_schema(schema):
"""Generate a JSON object based on a given JSON schema."""
schema_type = schema.get("type")
if schema_type == "object":
result = {}
properties = schema.get("properties", {})
for key, value in properties.items():
result[key] = generate_json_from_schema(value)
return result
elif schema_type == "array":
items = schema.get("items", {})
return [generate_json_from_schema(items)]
elif schema_type == "string":
return "string"
elif schema_type == "integer":
return 0
elif schema_type == "number":
return 0.0
elif schema_type == "boolean":
return False
elif schema_type == "null":
return None
else:
raise ValueError(f"Unsupported schema type: {schema_type}")