Skip to content

Commit 2099a97

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

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,9 @@ If you are carefully curating your `title` properties already to ensure no dupli
165165

166166
If this option results in conflicts, you will need to manually override class names instead via the `class_overrides` option.
167167

168+
### http_timeout
169+
170+
By default, the timeout for retrieving the schema file via HTTP is 5 seconds. In case there is an error when retrieving the schema, you might try and increase this setting to a higher value.
171+
168172
[changelog.md]: CHANGELOG.md
169173
[poetry]: https://python-poetry.org/

openapi_python_client/__init__.py

+3-3
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

+1
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)