csharp add timeout, fix default constructor

This commit is contained in:
wing328 2015-12-19 22:55:52 +08:00
parent 968c943c44
commit 0aa4d2fb8e
16 changed files with 98 additions and 56 deletions

View File

@ -24,15 +24,16 @@ namespace {{packageName}}.Client
/// <param name="apiKeyPrefix">Dictionary of API key prefix</param> /// <param name="apiKeyPrefix">Dictionary of API key prefix</param>
/// <param name="tempFolderPath">Temp folder path</param> /// <param name="tempFolderPath">Temp folder path</param>
/// <param name="dateTimeFormat">DateTime format string</param> /// <param name="dateTimeFormat">DateTime format string</param>
public Configuration(ApiClient apiClient, public Configuration(ApiClient apiClient = null,
Dictionary<String, String> defaultHeader, Dictionary<String, String> defaultHeader = null,
string username, string username = null,
string password, string password = null,
string accessToken, string accessToken = null,
Dictionary<String, String> apiKey, Dictionary<String, String> apiKey = null,
Dictionary<String, String> apiKeyPrefix, Dictionary<String, String> apiKeyPrefix = null,
string tempFolderPath, string tempFolderPath = null,
string dateTimeFormat string dateTimeFormat = null,
int timeout = 100
) )
{ {
if (apiClient == null) if (apiClient == null)
@ -43,19 +44,24 @@ namespace {{packageName}}.Client
Username = username; Username = username;
Password = password; Password = password;
AccessToken = accessToken; AccessToken = accessToken;
ApiKey = apiKey;
ApiKeyPrefix = apiKeyPrefix; if (defaultHeader != null)
DefaultHeader = defaultHeader;
if (apiKey != null)
ApiKey = apiKey;
if (apiKeyPrefix != null)
ApiKeyPrefix = apiKeyPrefix;
TempFolderPath = tempFolderPath; TempFolderPath = tempFolderPath;
DateTimeFormat = dateTimeFormat; DateTimeFormat = dateTimeFormat;
Timeout = timeout;
} }
/// <summary> /// <summary>
/// Initializes a new instance of the Configuration class. /// Initializes a new instance of the Configuration class.
/// </summary> /// </summary>
/// <param name="apiClient">Api client.</param> /// <param name="apiClient">Api client.</param>
public Configuration(ApiClient apiClient=null) public Configuration(ApiClient apiClient)
{ {
if (apiClient == null) if (apiClient == null)
ApiClient = ApiClient.Default; ApiClient = ApiClient.Default;
@ -75,20 +81,39 @@ namespace {{packageName}}.Client
/// <value>Configuration.</value> /// <value>Configuration.</value>
public static Configuration Default = new Configuration(); public static Configuration Default = new Configuration();
/// <summary>
/// Gets or sets the timeout value of ApiClient. Default to 100 seconds.
/// </summary>
/// <value>Timeout.</value>
public int Timeout
{
get { return ApiClient.RestClient.Timeout; }
set
{
ApiClient.RestClient.Timeout = value;
}
}
/// <summary> /// <summary>
/// Gets or sets the default API client for making HTTP calls. /// Gets or sets the default API client for making HTTP calls.
/// </summary> /// </summary>
/// <value>The API client.</value> /// <value>The API client.</value>
public ApiClient ApiClient; public ApiClient ApiClient;
private readonly Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>(); private Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>();
/// <summary> /// <summary>
/// Gets the default header. /// Gets or sets the default header.
/// </summary> /// </summary>
public Dictionary<String, String> DefaultHeader public Dictionary<String, String> DefaultHeader
{ {
get { return _defaultHeaderMap; } get { return _defaultHeaderMap; }
set
{
_defaultHeaderMap = value;
}
} }
/// <summary> /// <summary>

View File

@ -6,7 +6,6 @@ using RestSharp;
using IO.Swagger.Client; using IO.Swagger.Client;
using IO.Swagger.Model; using IO.Swagger.Model;
namespace IO.Swagger.Api namespace IO.Swagger.Api
{ {

View File

@ -6,7 +6,6 @@ using RestSharp;
using IO.Swagger.Client; using IO.Swagger.Client;
using IO.Swagger.Model; using IO.Swagger.Model;
namespace IO.Swagger.Api namespace IO.Swagger.Api
{ {

View File

@ -6,7 +6,6 @@ using RestSharp;
using IO.Swagger.Client; using IO.Swagger.Client;
using IO.Swagger.Model; using IO.Swagger.Model;
namespace IO.Swagger.Api namespace IO.Swagger.Api
{ {

View File

@ -24,15 +24,16 @@ namespace IO.Swagger.Client
/// <param name="apiKeyPrefix">Dictionary of API key prefix</param> /// <param name="apiKeyPrefix">Dictionary of API key prefix</param>
/// <param name="tempFolderPath">Temp folder path</param> /// <param name="tempFolderPath">Temp folder path</param>
/// <param name="dateTimeFormat">DateTime format string</param> /// <param name="dateTimeFormat">DateTime format string</param>
public Configuration(ApiClient apiClient, public Configuration(ApiClient apiClient = null,
Dictionary<String, String> defaultHeader, Dictionary<String, String> defaultHeader = null,
string username, string username = null,
string password, string password = null,
string accessToken, string accessToken = null,
Dictionary<String, String> apiKey, Dictionary<String, String> apiKey = null,
Dictionary<String, String> apiKeyPrefix, Dictionary<String, String> apiKeyPrefix = null,
string tempFolderPath, string tempFolderPath = null,
string dateTimeFormat string dateTimeFormat = null,
int timeout = 100
) )
{ {
if (apiClient == null) if (apiClient == null)
@ -43,19 +44,24 @@ namespace IO.Swagger.Client
Username = username; Username = username;
Password = password; Password = password;
AccessToken = accessToken; AccessToken = accessToken;
ApiKey = apiKey;
ApiKeyPrefix = apiKeyPrefix; if (defaultHeader != null)
DefaultHeader = defaultHeader;
if (apiKey != null)
ApiKey = apiKey;
if (apiKeyPrefix != null)
ApiKeyPrefix = apiKeyPrefix;
TempFolderPath = tempFolderPath; TempFolderPath = tempFolderPath;
DateTimeFormat = dateTimeFormat; DateTimeFormat = dateTimeFormat;
Timeout = timeout;
} }
/// <summary> /// <summary>
/// Initializes a new instance of the Configuration class. /// Initializes a new instance of the Configuration class.
/// </summary> /// </summary>
/// <param name="apiClient">Api client.</param> /// <param name="apiClient">Api client.</param>
public Configuration(ApiClient apiClient=null) public Configuration(ApiClient apiClient)
{ {
if (apiClient == null) if (apiClient == null)
ApiClient = ApiClient.Default; ApiClient = ApiClient.Default;
@ -75,20 +81,39 @@ namespace IO.Swagger.Client
/// <value>Configuration.</value> /// <value>Configuration.</value>
public static Configuration Default = new Configuration(); public static Configuration Default = new Configuration();
/// <summary>
/// Gets or sets the timeout value of ApiClient. Default to 100 seconds.
/// </summary>
/// <value>Timeout.</value>
public int Timeout
{
get { return ApiClient.RestClient.Timeout; }
set
{
ApiClient.RestClient.Timeout = value;
}
}
/// <summary> /// <summary>
/// Gets or sets the default API client for making HTTP calls. /// Gets or sets the default API client for making HTTP calls.
/// </summary> /// </summary>
/// <value>The API client.</value> /// <value>The API client.</value>
public ApiClient ApiClient; public ApiClient ApiClient;
private readonly Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>(); private Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>();
/// <summary> /// <summary>
/// Gets the default header. /// Gets or sets the default header.
/// </summary> /// </summary>
public Dictionary<String, String> DefaultHeader public Dictionary<String, String> DefaultHeader
{ {
get { return _defaultHeaderMap; } get { return _defaultHeaderMap; }
set
{
_defaultHeaderMap = value;
}
} }
/// <summary> /// <summary>

View File

@ -7,8 +7,6 @@ using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace IO.Swagger.Model namespace IO.Swagger.Model
{ {
@ -124,6 +122,4 @@ namespace IO.Swagger.Model
} }
} }
} }

View File

@ -7,8 +7,6 @@ using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace IO.Swagger.Model namespace IO.Swagger.Model
{ {
@ -189,6 +187,4 @@ namespace IO.Swagger.Model
} }
} }
} }

View File

@ -7,8 +7,6 @@ using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace IO.Swagger.Model namespace IO.Swagger.Model
{ {
@ -189,6 +187,4 @@ namespace IO.Swagger.Model
} }
} }
} }

View File

@ -7,8 +7,6 @@ using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace IO.Swagger.Model namespace IO.Swagger.Model
{ {
@ -124,6 +122,4 @@ namespace IO.Swagger.Model
} }
} }
} }

View File

@ -7,8 +7,6 @@ using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace IO.Swagger.Model namespace IO.Swagger.Model
{ {
@ -221,6 +219,4 @@ namespace IO.Swagger.Model
} }
} }
} }

View File

@ -107,5 +107,20 @@ namespace SwaggerClientTest.TestConfiguration
Assert.AreSame (p4.Configuration.ApiClient, a1); Assert.AreSame (p4.Configuration.ApiClient, a1);
} }
[Test ()]
public void TestTimeout ()
{
Configuration c1 = new Configuration();
Assert.AreEqual(c1.Timeout, 100); // default vaue
c1.Timeout = 10;
Assert.AreEqual(c1.Timeout, 10);
Configuration c2 = new Configuration(timeout: 20);
Assert.AreEqual(c2.Timeout, 20);
}
} }
} }

View File

@ -1,9 +1,9 @@
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.swagger-logo.png /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.swagger-logo.png
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll