2024-06-11 11:36:20 +00:00
|
|
|
import json
|
|
|
|
import os
|
2024-10-11 08:08:39 +00:00
|
|
|
|
2024-06-11 11:36:20 +00:00
|
|
|
from genson import SchemaBuilder
|
|
|
|
|
2024-10-11 08:08:39 +00:00
|
|
|
from conftest import option
|
|
|
|
|
2024-06-11 11:36:20 +00:00
|
|
|
|
|
|
|
class CustomSchemaBuilder(SchemaBuilder):
|
2024-10-11 08:08:39 +00:00
|
|
|
|
2024-06-11 11:36:20 +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)
|