add api response to C#

This commit is contained in:
wing328 2015-12-03 11:10:34 +08:00
parent cea8ad40cd
commit a5a4f8c7e0
14 changed files with 145 additions and 98 deletions

View File

@ -128,6 +128,8 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
sourceFolder + File.separator + clientPackage.replace(".", java.io.File.separator), "ApiClient.cs")); sourceFolder + File.separator + clientPackage.replace(".", java.io.File.separator), "ApiClient.cs"));
supportingFiles.add(new SupportingFile("ApiException.mustache", supportingFiles.add(new SupportingFile("ApiException.mustache",
sourceFolder + File.separator + clientPackage.replace(".", java.io.File.separator), "ApiException.cs")); sourceFolder + File.separator + clientPackage.replace(".", java.io.File.separator), "ApiException.cs"));
supportingFiles.add(new SupportingFile("ApiResponse.mustache",
sourceFolder + File.separator + clientPackage.replace(".", java.io.File.separator), "ApiResponse.cs"));
supportingFiles.add(new SupportingFile("Newtonsoft.Json.dll", "bin", "Newtonsoft.Json.dll")); supportingFiles.add(new SupportingFile("Newtonsoft.Json.dll", "bin", "Newtonsoft.Json.dll"));
supportingFiles.add(new SupportingFile("RestSharp.dll", "bin", "RestSharp.dll")); supportingFiles.add(new SupportingFile("RestSharp.dll", "bin", "RestSharp.dll"));
supportingFiles.add(new SupportingFile("compile.mustache", "", "compile.bat")); supportingFiles.add(new SupportingFile("compile.mustache", "", "compile.bat"));

View File

@ -1,47 +1,50 @@
using System; using System;
namespace {{packageName}}.Client { namespace {{packageName}}.Client
/// <summary> {
/// API Exception /// <summary>
/// </summary> /// API Exception
public class ApiException : Exception { /// </summary>
/// <summary> public class ApiException : Exception
/// Gets or sets the error code (HTTP status code) {
/// </summary> /// <summary>
/// <value>The error code (HTTP status code).</value> /// Gets or sets the error code (HTTP status code)
public int ErrorCode { get; set; } /// </summary>
/// <value>The error code (HTTP status code).</value>
/// <summary> public int ErrorCode { get; set; }
/// Gets or sets the error content (body json object)
/// </summary> /// <summary>
/// <value>The error content (Http response body).</value> /// Gets or sets the error content (body json object)
public dynamic ErrorContent { get; private set; } /// </summary>
/// <value>The error content (Http response body).</value>
/// <summary> public dynamic ErrorContent { get; private set; }
/// Initializes a new instance of the <see cref="ApiException"/> class.
/// </summary> /// <summary>
public ApiException() {} /// Initializes a new instance of the <see cref="ApiException"/> class.
/// </summary>
/// <summary> public ApiException() {}
/// Initializes a new instance of the <see cref="ApiException"/> class.
/// </summary> /// <summary>
/// <param name="errorCode">HTTP status code.</param> /// Initializes a new instance of the <see cref="ApiException"/> class.
/// <param name="message">Error message.</param> /// </summary>
public ApiException(int errorCode, string message) : base(message) { /// <param name="errorCode">HTTP status code.</param>
this.ErrorCode = errorCode; /// <param name="message">Error message.</param>
} public ApiException(int errorCode, string message) : base(message)
{
/// <summary> this.ErrorCode = errorCode;
/// Initializes a new instance of the <see cref="ApiException"/> class. }
/// </summary>
/// <param name="errorCode">HTTP status code.</param> /// <summary>
/// <param name="message">Error message.</param> /// Initializes a new instance of the <see cref="ApiException"/> class.
/// <param name="errorContent">Error content.</param> /// </summary>
public ApiException(int errorCode, string message, dynamic errorContent = null) : base(message) { /// <param name="errorCode">HTTP status code.</param>
this.ErrorCode = errorCode; /// <param name="message">Error message.</param>
this.ErrorContent = errorContent; /// <param name="errorContent">Error content.</param>
} public ApiException(int errorCode, string message, dynamic errorContent = null) : base(message)
{
} this.ErrorCode = errorCode;
this.ErrorContent = errorContent;
}
}
} }

View File

@ -72,7 +72,7 @@ namespace {{packageName}}.Api
/// <value>The base path</value> /// <value>The base path</value>
public String GetBasePath() public String GetBasePath()
{ {
return this.Configuration.BasePath; return this.Configuration.ApiClient.RestClient.BaseUrl.ToString();
} }
/// <summary> /// <summary>

View File

@ -221,7 +221,7 @@ namespace IO.Swagger.Api
/// <value>The base path</value> /// <value>The base path</value>
public String GetBasePath() public String GetBasePath()
{ {
return this.Configuration.BasePath; return this.Configuration.ApiClient.RestClient.BaseUrl.ToString();
} }
/// <summary> /// <summary>

View File

@ -129,7 +129,7 @@ namespace IO.Swagger.Api
/// <value>The base path</value> /// <value>The base path</value>
public String GetBasePath() public String GetBasePath()
{ {
return this.Configuration.BasePath; return this.Configuration.ApiClient.RestClient.BaseUrl.ToString();
} }
/// <summary> /// <summary>

View File

@ -213,7 +213,7 @@ namespace IO.Swagger.Api
/// <value>The base path</value> /// <value>The base path</value>
public String GetBasePath() public String GetBasePath()
{ {
return this.Configuration.BasePath; return this.Configuration.ApiClient.RestClient.BaseUrl.ToString();
} }
/// <summary> /// <summary>

View File

@ -1,47 +1,50 @@
using System; using System;
namespace IO.Swagger.Client { namespace IO.Swagger.Client
/// <summary> {
/// API Exception /// <summary>
/// </summary> /// API Exception
public class ApiException : Exception { /// </summary>
/// <summary> public class ApiException : Exception
/// Gets or sets the error code (HTTP status code) {
/// </summary> /// <summary>
/// <value>The error code (HTTP status code).</value> /// Gets or sets the error code (HTTP status code)
public int ErrorCode { get; set; } /// </summary>
/// <value>The error code (HTTP status code).</value>
/// <summary> public int ErrorCode { get; set; }
/// Gets or sets the error content (body json object)
/// </summary> /// <summary>
/// <value>The error content (Http response body).</value> /// Gets or sets the error content (body json object)
public dynamic ErrorContent { get; private set; } /// </summary>
/// <value>The error content (Http response body).</value>
/// <summary> public dynamic ErrorContent { get; private set; }
/// Initializes a new instance of the <see cref="ApiException"/> class.
/// </summary> /// <summary>
public ApiException() {} /// Initializes a new instance of the <see cref="ApiException"/> class.
/// </summary>
/// <summary> public ApiException() {}
/// Initializes a new instance of the <see cref="ApiException"/> class.
/// </summary> /// <summary>
/// <param name="errorCode">HTTP status code.</param> /// Initializes a new instance of the <see cref="ApiException"/> class.
/// <param name="message">Error message.</param> /// </summary>
public ApiException(int errorCode, string message) : base(message) { /// <param name="errorCode">HTTP status code.</param>
this.ErrorCode = errorCode; /// <param name="message">Error message.</param>
} public ApiException(int errorCode, string message) : base(message)
{
/// <summary> this.ErrorCode = errorCode;
/// Initializes a new instance of the <see cref="ApiException"/> class. }
/// </summary>
/// <param name="errorCode">HTTP status code.</param> /// <summary>
/// <param name="message">Error message.</param> /// Initializes a new instance of the <see cref="ApiException"/> class.
/// <param name="errorContent">Error content.</param> /// </summary>
public ApiException(int errorCode, string message, dynamic errorContent = null) : base(message) { /// <param name="errorCode">HTTP status code.</param>
this.ErrorCode = errorCode; /// <param name="message">Error message.</param>
this.ErrorContent = errorContent; /// <param name="errorContent">Error content.</param>
} public ApiException(int errorCode, string message, dynamic errorContent = null) : base(message)
{
} this.ErrorCode = errorCode;
this.ErrorContent = errorContent;
}
}
} }

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
namespace IO.Swagger.Client
{
/// <summary>
/// API Response
/// </summary>
public class ApiResponse<T>
{
/// <summary>
/// Gets or sets the status code (HTTP status code)
/// </summary>
/// <value>The status code.</value>
public int StatusCode { get; set; }
/// <summary>
/// Gets or sets the HTTP headers
/// </summary>
/// <value>HTTP headers</value>
public IDictionary<string, string> Headers { get; set; }
/// <summary>
/// Gets or sets the data (parsed HTTP body)
/// </summary>
/// <value>The data.</value>
public T Data { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="ApiResponse"/> class.
/// </summary>
/// <param name="statusCode">HTTP status code.</param>
/// <param name="message">Error message.</param>
/// <param name="data">Data (parsed HTTP body)</param>
public ApiResponse(int statusCode, IDictionary<string, string> headers, T data)
{
this.StatusCode= statusCode;
this.Headers = headers;
this.Data = data;
}
}
}

View File

@ -42,12 +42,6 @@ namespace IO.Swagger.Client
/// <value>The API client.</value> /// <value>The API client.</value>
public ApiClient ApiClient; public ApiClient ApiClient;
/// <summary>
/// Gets or sets the base path.
/// </summary>
/// <value>The base path</value>
public string BasePath { get; set; }
private readonly Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>(); private readonly Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>();
/// <summary> /// <summary>

View File

@ -57,6 +57,7 @@
<Compile Include="TestPet.cs" /> <Compile Include="TestPet.cs" />
<Compile Include="TestApiClient.cs" /> <Compile Include="TestApiClient.cs" />
<Compile Include="TestConfiguration.cs" /> <Compile Include="TestConfiguration.cs" />
<Compile Include="Lib\SwaggerClient\src\main\csharp\IO\Swagger\Client\ApiResponse.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>