Skip to content

Commit 501a6e1

Browse files
committed
fix: disable nonstandard response code handling by default
1 parent 0f6409d commit 501a6e1

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

openapi_python_client/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class ConfigFile(BaseModel):
4646
generate_all_tags: bool = False
4747
http_timeout: int = 5
4848
literal_enums: bool = False
49+
allow_int_response_codes: bool = False
4950

5051
@staticmethod
5152
def load_from_path(path: Path) -> "ConfigFile":
@@ -81,6 +82,7 @@ class Config:
8182
content_type_overrides: dict[str, str]
8283
overwrite: bool
8384
output_path: Path | None
85+
allow_int_response_codes: bool
8486

8587
@staticmethod
8688
def from_sources(
@@ -122,5 +124,6 @@ def from_sources(
122124
file_encoding=file_encoding,
123125
overwrite=overwrite,
124126
output_path=output_path,
127+
allow_int_response_codes=config_file.allow_int_response_codes
125128
)
126129
return config

openapi_python_client/templates/endpoint_module.py.jinja

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ from ... import errors
1111
{{ relative }}
1212
{% endfor %}
1313

14-
{% if endpoint.responses|list|length == 0 or endpoint.responses|map(attribute="status_code")|map(attribute="is_official")|all %}
14+
{% set all_standard_response_codes = endpoint.responses|map(attribute="status_code")|map(attribute="is_official")|all %}
15+
{% if config.allow_int_response_codes and not all_standard_response_codes %}
16+
HTTPStatus = int
17+
{% else %}
1518
import http
1619
HTTPStatus = http.HTTPStatus
17-
{% else %}
18-
HTTPStatus = int
1920
{% endif %}
2021

2122
{% from "endpoint_macros.py.jinja" import header_params, cookie_params, query_params,

0 commit comments

Comments
 (0)