Skip to content

[CSHARP] Duplicate headers causing exception #12529

@mihai80

Description

@mihai80

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions