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

[CSHARP] Duplicate headers causing exception #12529

Open
mihai80 opened this issue Mar 4, 2025 · 1 comment
Open

[CSHARP] Duplicate headers causing exception #12529

mihai80 opened this issue Mar 4, 2025 · 1 comment

Comments

@mihai80
Copy link

mihai80 commented Mar 4, 2025

When returning the ApiResponse, the method ToDictionary is used to construct a response object from a raw API response. The method ToDictionary will expect only unique keys, but this is not always the case. For example, headers could repeat which would cause the code to end in an exception.

Here is an example from the generated code:

            return new ApiResponse<KeycloakTokenResponse>(localVarStatusCode,
                localVarResponse.Headers.ToDictionary(x => x.Name, x => string.Join(",", x.Value)),
                (KeycloakTokenResponse) this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(KeycloakTokenResponse)));
nResponse) this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(KeycloakTokenResponse)));

and here is the modification I had to make:

            return new ApiResponse<KeycloakTokenResponse>(localVarStatusCode,
                localVarResponse.Headers.GroupBy(x => x.Name)
                    .ToDictionary(g => g.Key, g => g.Select(x => x.Value).ToString()),
                (KeycloakTokenResponse) this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(KeycloakTokenResponse)));

This workaround means that duplicates are allowed in the response headers. I believe this should be part of the generated code, but I am asking for any contrasting opinion.

@GutOFF
Copy link

GutOFF commented Mar 10, 2025

I encountered a similar problem

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

No branches or pull requests

2 participants