[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [Python] Cannot access multiple response headers with the same name #19154

Open
3 of 6 tasks
tom300z opened this issue Jul 12, 2024 · 2 comments
Open
3 of 6 tasks

Comments

@tom300z
Copy link
Contributor
tom300z commented Jul 12, 2024

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
    • Doesn't really make sense as this applies to any python client
  • Have you validated the input using an OpenAPI validator (example)?
    • Again not applicable
  • 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 am unable to access response headers that share the same name.

openapi-generator version

7.7.0

OpenAPI declaration file content or url

Irrelevant as the issue lies in the python client itself.

Steps to reproduce
  1. Generate a python client for any API that returns multiple headers with the same name
  2. Call an endpoint that should return full response information ExampleApi(...).xxx_with_http_info(...)
  3. Observe that ApiResponse.headers only contains the first header as dict keys are unique
Suggest a fix

I was able to work around this by overriding the templates locally and adding the following 2 lines.

diff --git a/modules/openapi-generator/src/main/resources/python/api_client.mustache b/modules/openapi-generator/src/main/resources/python/api_client.mustache
index c7d4a6d700f..dc9c9057cf9 100644
--- a/modules/openapi-generator/src/main/resources/python/api_client.mustache
+++ b/modules/openapi-generator/src/main/resources/python/api_client.mustache
@@ -335,6 +335,7 @@ class ApiClient:
             status_code = response_data.status,
             data = return_data,
             headers = response_data.getheaders(),
+            full_headers = tuple(response_data.getheaders().items()),
             raw_data = response_data.data
         )
 
diff --git a/modules/openapi-generator/src/main/resources/python/api_response.mustache b/modules/openapi-generator/src/main/resources/python/api_response.mustache
index 9bc7c11f6b9..136a745cb69 100644
--- a/modules/openapi-generator/src/main/resources/python/api_response.mustache
+++ b/modules/openapi-generator/src/main/resources/python/api_response.mustache
@@ -13,6 +13,7 @@ class ApiResponse(BaseModel, Generic[T]):
 
     status_code: StrictInt = Field(description="HTTP status code")
     headers: Optional[Mapping[str, str]] = Field(None, description="HTTP headers")
+    full_headers: tuple[tuple[str, str], ...] = Field(None, description="Full HTTP headers")
     data: T = Field(description="Deserialized data given the data type")
     raw_data: StrictBytes = Field(description="Raw data (HTTP response body)")
@wing328
Copy link
Member
wing328 commented Jul 14, 2024

@tom300z what about running tuple(api_response.headers.items()) using the existing headers field? would that meet your requirement?

@tom300z
Copy link
Contributor Author
tom300z commented Jul 15, 2024

Yes, that should work too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants