diff --git a/src/auto_reverse/doc/client.py b/src/auto_reverse/doc/client.py new file mode 100644 index 0000000..5ddeb0d --- /dev/null +++ b/src/auto_reverse/doc/client.py @@ -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 diff --git a/tests/test_client.py b/tests/test_client.py new file mode 100644 index 0000000..248891e --- /dev/null +++ b/tests/test_client.py @@ -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)