swagger-api / swagger-api/swagger-codegen

[CSharp Client] does not support Content-Types "application/soap+xml" and "application/xml"

Open
#6,591 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: C-Sharp Enhancement: Feature help wanted
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
  1. Generate the Csharp code using the json file attached
  2. Navigate to the method AppendLoggingEventWithHttpInfo() in the Api.DefaultAPI class
  3. 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
  4. Navigate to the the method Serialize() in the Client.ApiClient class
  5. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.