OpenAPITools / OpenAPITools/openapi-generator

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

Open
#22,436 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the four Python templates named in the issue: pyproject.mustache, requirements.mustache, setup.mustache, and the related import template changes from issue 22415. Reproduce generation with httpx specified and compare dependency output. Done means urllib3 is omitted when it is unnecessary while the other generated dependencies remain unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.