Skip to content

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

Open
@dnn01

Description

@dnn01
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":
#3870

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions