swagger-api/swagger-codegen

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

开放

#6,591 创建于 2017年9月29日

 (15 条评论) (0 个反应) (0 位负责人)HTML (5,474 个派生)batch import
Client: C-SharpEnhancement: Featurehelp wanted

仓库指标

星标
 (12,701 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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

贡献者指南