OpenAPITools / OpenAPITools/openapi-generator
C# client response headers invalid parsing
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
This issue was reported in swagger-codegen here.
The values in the headers dictionary in the ApiResponse class are not getting properly set since the type of the header values in the IHTTP headers interface is an IEnumerable<string>. This means that the x.Value.ToString() from the following code snippet evaluates to System.Collections.Generic.List`1[System.String]
public ApiResponse<Object> v1UserActivitiesDateDateJsonGetWithHttpInfo (string date) { ... return new ApiResponse<Object>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Key, x => x.Value.ToString()), null); }
Ideally, I think the type of the headers field in the ApiResponse class should be changed from an IDictionary<string, string> to an IDictionary<string, IEnumerable<string>> so that callers know that there can be multiple values per header. Would it be acceptable to make this fix or not since it would break existing API users?
Otherwise, we could take only the first header value or create a string that separates the different header values somehow like @omatrot suggested.
public ApiResponse<Object> v1UserActivitiesDateDateJsonGetWithHttpInfo (string date) { ... return new ApiResponse<Object>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Key, x => String.Join(",", x.Value.ToArray())), null); }
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect the generated C# ApiResponse class and the IHTTP headers interface referenced in the issue, then reproduce the shown WithHttpInfo header conversion. The issue does not settle whether to preserve multiple values, select one, or join them, so completion requires a maintainer decision and validation of the chosen behavior against generated client responses.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100