Generate tfl client

This commit is contained in:
Andras Schmelczer 2026-01-25 20:19:22 +00:00
parent caf943ed06
commit a7cc4d9b2b
5 changed files with 1274 additions and 1 deletions

43
generate_tfl_client.py Normal file
View file

@ -0,0 +1,43 @@
#!/usr/bin/env python3
# /// script
# requires-python = ">=3.12"
# dependencies = ["openapi-python-client"]
# ///
"""Regenerate the TfL Journey API client from the OpenAPI specification."""
# Run it with:
# uv run generate_tfl_client.py
import shutil
import subprocess
from pathlib import Path
OPENAPI_SPEC = Path("Journey.yaml")
OUTPUT_PATH = Path("tfl_journey_client")
def main() -> None:
if not OPENAPI_SPEC.exists():
raise FileNotFoundError(f"OpenAPI spec not found: {OPENAPI_SPEC}")
# Remove existing client if present
if OUTPUT_PATH.exists():
print(f"Removing existing client at {OUTPUT_PATH}")
shutil.rmtree(OUTPUT_PATH)
# Generate the client
print(f"Generating client from {OPENAPI_SPEC}")
result = subprocess.run(
["openapi-python-client", "generate", "--path", str(OPENAPI_SPEC), "--output-path", str(OUTPUT_PATH)],
check=True,
)
if result.returncode == 0:
print(f"Client generated successfully at {OUTPUT_PATH}")
else:
print("Client generation failed")
raise SystemExit(1)
if __name__ == "__main__":
main()