Generate tfl client
This commit is contained in:
parent
caf943ed06
commit
a7cc4d9b2b
5 changed files with 1274 additions and 1 deletions
43
generate_tfl_client.py
Normal file
43
generate_tfl_client.py
Normal 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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue