feat: optional typed client generation from openapi spec

This commit is contained in:
2026-06-01 01:10:38 +08:00
parent a9fa9457fc
commit 7d5870bbb4
2 changed files with 44 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
from __future__ import annotations
import subprocess
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from pathlib import Path
def client_gen_command(spec_path: Path, out_dir: Path) -> list[str]:
return [
"uvx",
"openapi-python-client",
"generate",
"--path",
str(spec_path),
"--output-path",
str(out_dir),
]
def generate_client(spec_path: Path, out_dir: Path) -> bool:
"""Run the deterministic codegen; returns True on success."""
try:
subprocess.run(client_gen_command(spec_path, out_dir), check=True)
return True
except (subprocess.CalledProcessError, FileNotFoundError):
return False
+16
View File
@@ -0,0 +1,16 @@
from __future__ import annotations
from typing import TYPE_CHECKING
from auto_reverse.doc.client import client_gen_command
if TYPE_CHECKING:
from pathlib import Path
def test_command_references_spec_and_out(tmp_path: Path):
spec = tmp_path / "openapi.yaml"
out = tmp_path / "client"
cmd = client_gen_command(spec, out)
assert str(spec) in cmd
assert "openapi-python-client" in " ".join(cmd)