swagger-api / swagger-api/swagger-codegen
[CSharp Client] does not support Content-Types "application/soap+xml" and "application/xml"
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I generated a CSharp client from the attached Json file and the content type is correctly identified as application/soap+xml. However, the client does not appear to support this content type.
To perform the XML POST, the call to serialize the body is:
if (body != null && body.GetType() != typeof(byte[]))
{
localVarPostBody = Configuration.ApiClient.Serialize(body); // http body (model) parameter
}
else
{
localVarPostBody = body; // byte array
}
The serialize method in the API client is:
public String Serialize(object obj)
{
try
{
return obj != null ? JsonConvert.SerializeObject(obj) : null;
}
catch (Exception e)
{
throw new ApiException(500, e.Message);
}
}
In the prepare request method:
if (postBody != null) // http body (model or byte[]) parameter
{
if (postBody.GetType() == typeof(String))
{
request.AddParameter("application/json", postBody, ParameterType.RequestBody);
}
else if (postBody.GetType() == typeof(byte[]))
{
request.AddParameter(contentType, postBody, ParameterType.RequestBody);
}
}
return request;
Swagger-codegen version
Version 2.2.3 (swagger-codegen-cli-2.2.3.jar)
Also tried Version 2.3.0 (swagger-codegen-cli-2.3.0-20170923.081757-145.jar) with the same result
Swagger declaration file content or url
The json file is:
(Log4NetService.zip)
Note: this Swagger definition was created from the WSDL of the backend service using apiconnect-wsdl
Command line used for generation
java -jar swagger-codegen-cli-2.2.3.jar generate -i Log4NetService.json -l csharp
Steps to reproduce
- Generate the Csharp code using the json file attached
- Navigate to the method AppendLoggingEventWithHttpInfo() in the Api.DefaultAPI class
- Note that the call localVarPostBody = Configuration.ApiClient.Serialize(body) to the Serialize method does not pass in content type, even though it is available in localVarHttpContentType
- Navigate to the the method Serialize() in the Client.ApiClient class
- Note that the method only supports json
Related issues/PRs
Default Java client does not support Content-Type "application/xml":
https://github.com/swagger-api/swagger-codegen/issues/3870
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
Start by generating the C# client with the attached Log4NetService.json using the listed swagger-codegen command, then inspect DefaultAPI.AppendLoggingEventWithHttpInfo(), ApiClient.Serialize(), and the prepare request method. Trace how localVarHttpContentType reaches request construction; done means application/soap+xml and application/xml requests are serialized and sent using their declared content types instead of only JSON.
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
- Mostly clear
- Newbie friendliness
- 32/100