Skip to content

Commit d32778e

Browse files
committed
Fix CI
1 parent eea448a commit d32778e

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

src/openapi_client/cli.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def main() -> None:
447447
from_openapi_parser = subparsers.add_parser(
448448
"from_openapi", help="Generate code from OpenAPI"
449449
)
450-
450+
451451
group = from_openapi_parser.add_mutually_exclusive_group(required=False)
452452
group.add_argument("-i", "--input", type=str, help="Path to OpenAPI JSON file")
453453
group.add_argument(
@@ -565,9 +565,6 @@ def main() -> None:
565565
)
566566
elif args.command == "to_openapi":
567567
in_path = args.input
568-
if not in_path:
569-
to_openapi_parser.print_help()
570-
sys.exit(1)
571568
sync_to_openapi(in_path, args.output)
572569
elif args.command == "to_docs_json":
573570
generate_docs_json(args.input, args.no_imports, args.no_wrapping, args.output)

tests/test_cli_sync_to_openapi.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import json
2+
from pathlib import Path
3+
from openapi_client.cli import sync_to_openapi
4+
5+
def test_sync_to_openapi_dir(tmp_path: Path) -> None:
6+
project_dir = tmp_path / "project"
7+
project_dir.mkdir()
8+
9+
client_py = project_dir / "client.py"
10+
client_py.write_text("class Client:\n pass\n")
11+
12+
mock_py = project_dir / "mock_server.py"
13+
mock_py.write_text("def test_mock():\n pass\n")
14+
15+
test_py = project_dir / "test_client.py"
16+
test_py.write_text("def test_client():\n pass\n")
17+
18+
cli_py = project_dir / "cli_main.py"
19+
cli_py.write_text("import argparse\n")
20+
21+
out_file = tmp_path / "openapi.json"
22+
sync_to_openapi(str(project_dir), str(out_file))
23+
24+
assert out_file.exists()
25+
data = json.loads(out_file.read_text())
26+
assert "openapi" in data
27+
28+
def test_sync_to_openapi_empty_output(tmp_path: Path) -> None:
29+
# Test when output_path is not given (it defaults to "openapi.json")
30+
import os
31+
old_cwd = os.getcwd()
32+
os.chdir(str(tmp_path))
33+
try:
34+
project_dir = tmp_path / "project2"
35+
project_dir.mkdir()
36+
client_py = project_dir / "client.py"
37+
client_py.write_text("class Client:\n pass\n")
38+
sync_to_openapi(str(project_dir), "")
39+
assert (tmp_path / "openapi.json").exists()
40+
finally:
41+
os.chdir(old_cwd)

0 commit comments

Comments
 (0)