activity-core/scripts/export_schemas.py

36 lines
850 B
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
"""
Export JSON Schemas for the core domain models.
Usage:
python scripts/export_schemas.py
Output:
schemas/event-envelope.json
schemas/activity-definition.json
Run this whenever models.py changes.
"""
import json
from pathlib import Path
from activity_core.models import ActivityDefinition, EventEnvelope
SCHEMAS_DIR = Path(__file__).parent.parent / "schemas"
SCHEMAS_DIR.mkdir(exist_ok=True)
def export(model, filename: str) -> None:
schema = model.model_json_schema()
path = SCHEMAS_DIR / filename
path.write_text(json.dumps(schema, indent=2))
print(f" wrote {path.relative_to(Path.cwd())}")
if __name__ == "__main__":
print("Exporting JSON schemas...")
export(EventEnvelope, "event-envelope.json")
export(ActivityDefinition, "activity-definition.json")
print("Done.")