Skip to content

Commit 383f763

Browse files
committed
Clean up output
- Hide black/isort output - Better file exists error - More info on unsupported content_type
1 parent 3909b00 commit 383f763

File tree

6 files changed

+36
-8
lines changed

6 files changed

+36
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
- Support for any supported property within a list (array), including other lists.
2020
- Support for Union types ("anyOf" in OpenAPI document)
2121
- Support for more basic response types (integer, number, boolean)
22-
- Better error messages when failing to parse an OpenAPI document
23-
- Error messages will contain some useful information about why it failed instead of just a stack trace
24-
- Client will still be generated if there are errors, excluding endpoints that had errors
2522

2623
### Changes
2724
- The way most imports are handled was changed which *should* lead to fewer unused imports in generated files.
25+
- Better error messages
26+
- Most error messages will contain some useful information about why it failed instead of a stack trace
27+
- Client will still be generated if there are recoverable errors, excluding endpoints that had those errors
28+
- Output from isort and black when generating will now be suppressed
2829

2930
## 0.3.0 - 2020-04-25
3031
### Additions

openapi_python_client/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,14 @@ def update(self) -> None:
105105
self._raise_errors()
106106

107107
def _reformat(self) -> None:
108-
subprocess.run("isort --recursive --apply", cwd=self.project_dir, shell=True)
109-
subprocess.run("black .", cwd=self.project_dir, shell=True)
108+
subprocess.run(
109+
"isort --recursive --apply",
110+
cwd=self.project_dir,
111+
shell=True,
112+
stdout=subprocess.PIPE,
113+
stderr=subprocess.PIPE,
114+
)
115+
subprocess.run("black .", cwd=self.project_dir, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
110116

111117
def _raise_errors(self) -> None:
112118
errors = []

openapi_python_client/cli.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ def handle_errors() -> Generator[None, None, None]:
6868
for err in e.parse_errors:
6969
_print_parser_error(err)
7070
raise typer.Exit(code=1)
71+
except FileExistsError:
72+
typer.secho("Directory already exists. Delete it or use the update command.", fg=typer.colors.RED, err=True)
73+
raise typer.Exit(code=1)
7174

7275

7376
@app.command()

openapi_python_client/openapi_parser/responses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def response_from_dict(*, status_code: int, data: _ResponseDict) -> Response:
9696
elif "text/html" in content:
9797
content_type = "text/html"
9898
else:
99-
raise ParseError(data)
99+
raise ParseError(data, message=f"Unsupported content_type {content}")
100100

101101
schema_data = data["content"][content_type]["schema"]
102102

tests/test___init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ def test__build_api(self, mocker):
435435

436436

437437
def test__reformat(mocker):
438+
import subprocess
438439
from openapi_python_client import _Project, OpenAPI
439440

440441
sub_run = mocker.patch("subprocess.run")
@@ -446,8 +447,14 @@ def test__reformat(mocker):
446447

447448
sub_run.assert_has_calls(
448449
[
449-
mocker.call("isort --recursive --apply", cwd=project.project_dir, shell=True),
450-
mocker.call("black .", cwd=project.project_dir, shell=True),
450+
mocker.call(
451+
"isort --recursive --apply",
452+
cwd=project.project_dir,
453+
shell=True,
454+
stdout=subprocess.PIPE,
455+
stderr=subprocess.PIPE,
456+
),
457+
mocker.call("black .", cwd=project.project_dir, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE),
451458
]
452459
)
453460

tests/test_cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ def test_generate_handle_multiple_parse_error(self, _create_new_client):
128128
"Please open an issue at https://github.com/triaxtec/openapi-python-client/issues/new/choose\n\n"
129129
)
130130

131+
def test_generate_handle_file_exists(self, _create_new_client):
132+
error = FileExistsError()
133+
_create_new_client.side_effect = error
134+
path = "cool/path"
135+
from openapi_python_client.cli import app
136+
137+
result = runner.invoke(app, ["generate", f"--path={path}"])
138+
139+
assert result.exit_code == 1
140+
assert result.output == "Directory already exists. Delete it or use the update command.\n"
141+
131142

132143
@pytest.fixture
133144
def _update_existing_client(mocker):

0 commit comments

Comments
 (0)