Skip to content

Commit b0c5e1b

Browse files
committed
feat: add detail to ParseError when parsing response fails
1 parent 7955faa commit b0c5e1b

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
@@ -248,10 +248,11 @@ def _add_responses(
248248
status_code=status_code, data=response_data, schemas=schemas, parent_name=endpoint.name, config=config
249249
)
250250
if isinstance(response, ParseError):
251+
detail_suffix = "" if response.detail is None else f" ({response.detail})"
251252
endpoint.errors.append(
252253
ParseError(
253254
detail=(
254-
f"Cannot parse response for status code {status_code}, "
255+
f"Cannot parse response for status code {status_code}{detail_suffix}, "
255256
f"response will be ommitted from generated client"
256257
),
257258
data=response.data,

tests/test_parser/test_openapi.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def test__add_responses_error(self, mocker):
416416
"404": response_2_data,
417417
}
418418
endpoint = self.make_endpoint()
419-
parse_error = ParseError(data=mocker.MagicMock())
419+
parse_error = ParseError(data=mocker.MagicMock(), detail="some problem")
420420
response_from_data = mocker.patch(f"{MODULE_NAME}.response_from_data", return_value=(parse_error, schemas))
421421
config = MagicMock()
422422

@@ -430,11 +430,13 @@ def test__add_responses_error(self, mocker):
430430
)
431431
assert response.errors == [
432432
ParseError(
433-
detail=f"Cannot parse response for status code 200, response will be ommitted from generated client",
433+
detail=f"Cannot parse response for status code 200 (some problem), "
434+
"response will be ommitted from generated client",
434435
data=parse_error.data,
435436
),
436437
ParseError(
437-
detail=f"Cannot parse response for status code 404, response will be ommitted from generated client",
438+
detail=f"Cannot parse response for status code 404 (some problem), "
439+
"response will be ommitted from generated client",
438440
data=parse_error.data,
439441
),
440442
]

0 commit comments

Comments
 (0)