status-go/tests-functional/schema_builder.py

23 lines
604 B
Python
Raw Normal View History

import json
import os
2024-10-11 08:08:39 +00:00
from genson import SchemaBuilder
2024-10-11 08:08:39 +00:00
from conftest import option
class CustomSchemaBuilder(SchemaBuilder):
2024-10-11 08:08:39 +00:00
def __init__(self, schema_name):
super().__init__()
self.path = f"{option.base_dir}/schemas/{schema_name}"
def create_schema(self, response_json):
builder = SchemaBuilder()
builder.add_object(response_json)
schema = builder.to_schema()
os.makedirs(os.path.dirname(self.path), exist_ok=True)
with open(self.path, "w") as file:
json.dump(schema, file, sort_keys=True, indent=4, ensure_ascii=False)