openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] [Python] Configuration template unconditionally dependency on urllib3 when httpx is specified

Open saschakr opened this issue 1 month ago • 3 comments

Bug Report Checklist

  • [ ] Have you provided a full/minimal spec to reproduce the issue?
  • [ ] Have you validated the input using an OpenAPI validator?
  • [x] Have you tested with the latest master to confirm the issue still exists?
  • [x] Have you searched for related issues/PRs?
  • [ ] What's the actual output vs expected output?
  • [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I saw the bugfix from issue https://github.com/OpenAPITools/openapi-generator/issues/22415 but there are still the dependency on urllib3 on the template which are generated always. while there are no more imports on urllib3 there is still the (unnecessary) dependency

Generated Code by version 1.18.0-SNAPSHOT:

pyproject.toml

dependencies = [
  "urllib3 (>=2.1.0,<3.0.0)",
  "python-dateutil (>=2.8.2)",

requirements.txt

urllib3 >= 2.1.0, < 3.0.0

setup.py

REQUIRES = [
    "urllib3 >= 2.1.0, < 3.0.0",
openapi-generator version

latest master (7.18.0-SNAPSHOT)

OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs

related issue: https://github.com/OpenAPITools/openapi-generator/issues/22415 related merge request: https://github.com/OpenAPITools/openapi-generator/pull/22418

Suggest a fix

Depending on the related mr there should be surrounding {{^async}} blocks on the imports of the urllib3 like that patch

diff --git a/modules/openapi-generator/src/main/resources/python/pyproject.mustache b/modules/openapi-generator/src/main/resources/python/pyproject.mustache
index 6cd7936be55..7eed997a3f4 100644
--- a/modules/openapi-generator/src/main/resources/python/pyproject.mustache
+++ b/modules/openapi-generator/src/main/resources/python/pyproject.mustache
@@ -33,7 +33,9 @@ include = ["{{packageName}}/py.typed"]
 
 [tool.poetry.dependencies]
 python = "^3.9"
+{{^async}}
 urllib3 = ">= 2.1.0, < 3.0.0"
+{{/async}}
 python-dateutil = ">= 2.8.2"
 {{#asyncio}}
 aiohttp = ">= 3.8.4"
@@ -59,7 +61,9 @@ lazy-imports = ">= 1, < 2"
 requires-python = ">=3.9"
 
 dependencies = [
+{{^async}}
   "urllib3 (>=2.1.0,<3.0.0)",
+{{/async}}
   "python-dateutil (>=2.8.2)",
 {{#httpx}}
   "httpx (>=0.28.1)",
diff --git a/modules/openapi-generator/src/main/resources/python/requirements.mustache b/modules/openapi-generator/src/main/resources/python/requirements.mustache
index ee103eba2d7..aef16e4cb7a 100644
--- a/modules/openapi-generator/src/main/resources/python/requirements.mustache
+++ b/modules/openapi-generator/src/main/resources/python/requirements.mustache
@@ -1,4 +1,6 @@
+{{^async}}
 urllib3 >= 2.1.0, < 3.0.0
+{{/async}}
 python_dateutil >= 2.8.2
 {{#asyncio}}
 aiohttp >= 3.8.4
diff --git a/modules/openapi-generator/src/main/resources/python/setup.mustache b/modules/openapi-generator/src/main/resources/python/setup.mustache
index b4589687b17..d65485b42f9 100644
--- a/modules/openapi-generator/src/main/resources/python/setup.mustache
+++ b/modules/openapi-generator/src/main/resources/python/setup.mustache
@@ -15,7 +15,9 @@ NAME = "{{{projectName}}}"
 VERSION = "{{packageVersion}}"
 PYTHON_REQUIRES = ">= 3.9"
 REQUIRES = [
+{{^async}}
     "urllib3 >= 2.1.0, < 3.0.0",
+{{/async}}
     "python-dateutil >= 2.8.2",
 {{#asyncio}}
     "aiohttp >= 3.8.4",

I tested this patch on my project and there are no more dependencies on urllib3, but tbh I cannot say if there are some hidden issues with that patch.

Please let me know if you need any more information.

saschakr avatar Nov 25 '25 22:11 saschakr

can you please file a PR with the suggested change and we will review accordingly?

wing328 avatar Nov 26 '25 09:11 wing328

cc @jwulf (author of #22418)

wing328 avatar Nov 26 '25 10:11 wing328

can you please file a PR with the suggested change and we will review accordingly?

Created: https://github.com/OpenAPITools/openapi-generator/pull/22441

saschakr avatar Nov 26 '25 10:11 saschakr