Skip to content

Commit 7b2fd5d

Browse files
committed
Add http_timeout configuration setting to configure timeout when getting document via HTTP.
1 parent 298cc5a commit 7b2fd5d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

openapi_python_client/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def _get_project_for_url_or_path( # pylint: disable=too-many-arguments
311311
custom_template_path: Optional[Path] = None,
312312
file_encoding: str = "utf-8",
313313
) -> Union[Project, GeneratorError]:
314-
data_dict = _get_document(url=url, path=path)
314+
data_dict = _get_document(url=url, path=path, timeout=config.http_timeout)
315315
if isinstance(data_dict, GeneratorError):
316316
return data_dict
317317
openapi = GeneratorData.from_dict(data_dict, config=config)
@@ -395,14 +395,14 @@ def _load_yaml_or_json(data: bytes, content_type: Optional[str]) -> Union[Dict[s
395395
return GeneratorError(header=f"Invalid YAML from provided source: {err}")
396396

397397

398-
def _get_document(*, url: Optional[str], path: Optional[Path]) -> Union[Dict[str, Any], GeneratorError]:
398+
def _get_document(*, url: Optional[str], path: Optional[Path], timeout: int) -> Union[Dict[str, Any], GeneratorError]:
399399
yaml_bytes: bytes
400400
content_type: Optional[str]
401401
if url is not None and path is not None:
402402
return GeneratorError(header="Provide URL or Path, not both.")
403403
if url is not None:
404404
try:
405-
response = httpx.get(url)
405+
response = httpx.get(url, timeout=timeout)
406406
yaml_bytes = response.content
407407
if "content-type" in response.headers:
408408
content_type = response.headers["content-type"].split(";")[0]

openapi_python_client/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Config(BaseModel):
3434
"black .",
3535
]
3636
field_prefix: str = "field_"
37+
http_timeout: int = 5
3738

3839
@staticmethod
3940
def load_from_path(path: Path) -> "Config":

0 commit comments

Comments
 (0)