Skip to content

Commit 5225cb7

Browse files
committed
parser / openapi / softly ignore invalid resp status code
1 parent af09640 commit 5225cb7

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

openapi_python_client/parser/openapi.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,29 @@ def _add_body(
169169
def _add_responses(*, endpoint: "Endpoint", data: oai.Responses, schemas: Schemas) -> Tuple["Endpoint", Schemas]:
170170
endpoint = deepcopy(endpoint)
171171
for code, response_data in data.items():
172+
173+
status_code: int
174+
try:
175+
status_code = int(code)
176+
except ValueError:
177+
endpoint.errors.append(
178+
ParseError(
179+
detail=(
180+
f"Invalid response status code {code} (not a number),"
181+
f"response will be ommitted from generated client"
182+
)
183+
)
184+
)
185+
continue
186+
172187
response, schemas = response_from_data(
173-
status_code=int(code), data=response_data, schemas=schemas, parent_name=endpoint.name
188+
status_code=status_code, data=response_data, schemas=schemas, parent_name=endpoint.name
174189
)
175190
if isinstance(response, ParseError):
176191
endpoint.errors.append(
177192
ParseError(
178193
detail=(
179-
f"Cannot parse response for status code {code}, "
194+
f"Cannot parse response for status code {status_code}, "
180195
f"response will be ommitted from generated client"
181196
),
182197
data=response.data,

0 commit comments

Comments
 (0)