mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-04 22:50:53 +00:00
add api response to C#
This commit is contained in:
parent
cea8ad40cd
commit
a5a4f8c7e0
@ -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"));
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace {{packageName}}.Client {
|
namespace {{packageName}}.Client
|
||||||
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// API Exception
|
/// API Exception
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ApiException : Exception {
|
public class ApiException : Exception
|
||||||
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the error code (HTTP status code)
|
/// Gets or sets the error code (HTTP status code)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -27,7 +29,8 @@ namespace {{packageName}}.Client {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="errorCode">HTTP status code.</param>
|
/// <param name="errorCode">HTTP status code.</param>
|
||||||
/// <param name="message">Error message.</param>
|
/// <param name="message">Error message.</param>
|
||||||
public ApiException(int errorCode, string message) : base(message) {
|
public ApiException(int errorCode, string message) : base(message)
|
||||||
|
{
|
||||||
this.ErrorCode = errorCode;
|
this.ErrorCode = errorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,11 +40,11 @@ namespace {{packageName}}.Client {
|
|||||||
/// <param name="errorCode">HTTP status code.</param>
|
/// <param name="errorCode">HTTP status code.</param>
|
||||||
/// <param name="message">Error message.</param>
|
/// <param name="message">Error message.</param>
|
||||||
/// <param name="errorContent">Error content.</param>
|
/// <param name="errorContent">Error content.</param>
|
||||||
public ApiException(int errorCode, string message, dynamic errorContent = null) : base(message) {
|
public ApiException(int errorCode, string message, dynamic errorContent = null) : base(message)
|
||||||
|
{
|
||||||
this.ErrorCode = errorCode;
|
this.ErrorCode = errorCode;
|
||||||
this.ErrorContent = errorContent;
|
this.ErrorContent = errorContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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>
|
||||||
|
@ -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>
|
||||||
|
@ -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>
|
||||||
|
@ -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>
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace IO.Swagger.Client {
|
namespace IO.Swagger.Client
|
||||||
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// API Exception
|
/// API Exception
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ApiException : Exception {
|
public class ApiException : Exception
|
||||||
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the error code (HTTP status code)
|
/// Gets or sets the error code (HTTP status code)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -27,7 +29,8 @@ namespace IO.Swagger.Client {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="errorCode">HTTP status code.</param>
|
/// <param name="errorCode">HTTP status code.</param>
|
||||||
/// <param name="message">Error message.</param>
|
/// <param name="message">Error message.</param>
|
||||||
public ApiException(int errorCode, string message) : base(message) {
|
public ApiException(int errorCode, string message) : base(message)
|
||||||
|
{
|
||||||
this.ErrorCode = errorCode;
|
this.ErrorCode = errorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,11 +40,11 @@ namespace IO.Swagger.Client {
|
|||||||
/// <param name="errorCode">HTTP status code.</param>
|
/// <param name="errorCode">HTTP status code.</param>
|
||||||
/// <param name="message">Error message.</param>
|
/// <param name="message">Error message.</param>
|
||||||
/// <param name="errorContent">Error content.</param>
|
/// <param name="errorContent">Error content.</param>
|
||||||
public ApiException(int errorCode, string message, dynamic errorContent = null) : base(message) {
|
public ApiException(int errorCode, string message, dynamic errorContent = null) : base(message)
|
||||||
|
{
|
||||||
this.ErrorCode = errorCode;
|
this.ErrorCode = errorCode;
|
||||||
this.ErrorContent = errorContent;
|
this.ErrorContent = errorContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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>
|
||||||
|
@ -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>
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user