Skip to content

Commit 0a0d44b

Browse files
supermihidbanty
andauthored
feat: improve the error message when parsing a response fails [#659]. Thanks @supermihi!
Co-authored-by: Dylan Anthony <[email protected]>
1 parent 4f9f03a commit 0a0d44b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

openapi_python_client/parser/openapi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,11 @@ def _add_responses(
274274
status_code=status_code, data=response_data, schemas=schemas, parent_name=endpoint.name, config=config
275275
)
276276
if isinstance(response, ParseError):
277+
detail_suffix = "" if response.detail is None else f" ({response.detail})"
277278
endpoint.errors.append(
278279
ParseError(
279280
detail=(
280-
f"Cannot parse response for status code {status_code}, "
281+
f"Cannot parse response for status code {status_code}{detail_suffix}, "
281282
f"response will be ommitted from generated client"
282283
),
283284
data=response.data,

tests/test_parser/test_openapi.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def test__add_responses_error(self, mocker):
460460
"404": response_2_data,
461461
}
462462
endpoint = self.make_endpoint()
463-
parse_error = ParseError(data=mocker.MagicMock())
463+
parse_error = ParseError(data=mocker.MagicMock(), detail="some problem")
464464
response_from_data = mocker.patch(f"{MODULE_NAME}.response_from_data", return_value=(parse_error, schemas))
465465
config = MagicMock()
466466

@@ -474,11 +474,13 @@ def test__add_responses_error(self, mocker):
474474
)
475475
assert response.errors == [
476476
ParseError(
477-
detail=f"Cannot parse response for status code 200, response will be ommitted from generated client",
477+
detail=f"Cannot parse response for status code 200 (some problem), "
478+
"response will be ommitted from generated client",
478479
data=parse_error.data,
479480
),
480481
ParseError(
481-
detail=f"Cannot parse response for status code 404, response will be ommitted from generated client",
482+
detail=f"Cannot parse response for status code 404 (some problem), "
483+
"response will be ommitted from generated client",
482484
data=parse_error.data,
483485
),
484486
]

0 commit comments

Comments
 (0)