diff --git a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache
index 049f8814fc3..3b83a33c889 100644
--- a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache
+++ b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache
@@ -61,7 +61,8 @@ namespace {{packageName}}.Client
/// Gets or sets the default API client for making HTTP calls.
///
/// The default API client.
- public static ApiClient Default = new ApiClient(Configuration.Default);
+ [Obsolete("ApiClient.Default is deprecated, please use 'Configuraiton.Default.ApiClient' instead.")]
+ public static ApiClient Default;
///
/// Gets or sets the Configuration.
diff --git a/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache b/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache
index a7e5df5179c..e7a19003e15 100644
--- a/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache
+++ b/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache
@@ -37,10 +37,7 @@ namespace {{packageName}}.Client
int timeout = 100000
)
{
- if (apiClient == null)
- ApiClient = ApiClient.Default == null ? new ApiClient() : ApiClient.Default;
- else
- ApiClient = apiClient;
+ setApiClientUsingDefault(apiClient);
Username = username;
Password = password;
@@ -64,18 +61,15 @@ namespace {{packageName}}.Client
/// Api client.
public Configuration(ApiClient apiClient)
{
- if (apiClient == null)
- ApiClient = ApiClient.Default;
- else
- ApiClient = apiClient;
+ setApiClientUsingDefault(apiClient);
}
-
+
///
/// Version of the package.
///
/// Version of the package.
public const string Version = "{{packageVersion}}";
-
+
///
/// Gets or sets the default Configuration.
///
@@ -103,8 +97,31 @@ namespace {{packageName}}.Client
/// The API client.
public ApiClient ApiClient;
+ ///
+ /// Set the ApiClient using Default or ApiClient instance
+ ///
+ /// An instance of ApiClient
+ ///
+ public void setApiClientUsingDefault (ApiClient apiClient = null)
+ {
+ if (apiClient == null)
+ {
+ if (Default != null && Default.ApiClient == null)
+ Default.ApiClient = new ApiClient();
+
+ ApiClient = Default != null ? Default.ApiClient : new ApiClient();
+ }
+ else
+ {
+ if (Default != null && Default.ApiClient == null)
+ Default.ApiClient = apiClient;
+
+ ApiClient = apiClient;
+ }
+ }
+
private Dictionary _defaultHeaderMap = new Dictionary();
-
+
///
/// Gets or sets the default header.
///
@@ -134,13 +151,13 @@ namespace {{packageName}}.Client
///
/// The username.
public String Username { get; set; }
-
+
///
/// Gets or sets the password (HTTP basic authentication).
///
/// The password.
public String Password { get; set; }
-
+
///
/// Gets or sets the access token for OAuth2 authentication.
///
@@ -152,7 +169,7 @@ namespace {{packageName}}.Client
///
/// The API key.
public Dictionary ApiKey = new Dictionary();
-
+
///
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name.
///
@@ -174,9 +191,9 @@ namespace {{packageName}}.Client
else
return apiKeyValue;
}
-
+
private string _tempFolderPath = Path.GetTempPath();
-
+
///
/// Gets or sets the temporary folder path to store the files downloaded from the server.
///
@@ -184,19 +201,19 @@ namespace {{packageName}}.Client
public String TempFolderPath
{
get { return _tempFolderPath; }
-
- set
+
+ set
{
if (String.IsNullOrEmpty(value))
{
_tempFolderPath = value;
return;
}
-
+
// create the directory if it does not exist
if (!Directory.Exists(value))
Directory.CreateDirectory(value);
-
+
// check if the path contains directory separator at the end
if (value[value.Length - 1] == Path.DirectorySeparatorChar)
_tempFolderPath = value;
@@ -251,7 +268,7 @@ namespace {{packageName}}.Client
.Where(x => x.Name == "System.Core").First().Version.ToString() + "\n";
report += " Version of the API: {{version}}\n";
report += " SDK Package Version: {{packageVersion}}\n";
-
+
return report;
}
}
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs
index 9ebd05fa731..70b17804f65 100644
--- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs
+++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs
@@ -61,7 +61,8 @@ namespace IO.Swagger.Client
/// Gets or sets the default API client for making HTTP calls.
///
/// The default API client.
- public static ApiClient Default = new ApiClient(Configuration.Default);
+ [Obsolete("ApiClient.Default is deprecated, please use 'Configuraiton.Default.ApiClient' instead.")]
+ public static ApiClient Default;
///
/// Gets or sets the Configuration.
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs
index d321ad5ef82..e55fc875f42 100644
--- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs
+++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs
@@ -37,10 +37,7 @@ namespace IO.Swagger.Client
int timeout = 100000
)
{
- if (apiClient == null)
- ApiClient = ApiClient.Default == null ? new ApiClient() : ApiClient.Default;
- else
- ApiClient = apiClient;
+ setApiClientUsingDefault(apiClient);
Username = username;
Password = password;
@@ -64,18 +61,15 @@ namespace IO.Swagger.Client
/// Api client.
public Configuration(ApiClient apiClient)
{
- if (apiClient == null)
- ApiClient = ApiClient.Default;
- else
- ApiClient = apiClient;
+ setApiClientUsingDefault(apiClient);
}
-
+
///
/// Version of the package.
///
/// Version of the package.
public const string Version = "1.0.0";
-
+
///
/// Gets or sets the default Configuration.
///
@@ -103,8 +97,31 @@ namespace IO.Swagger.Client
/// The API client.
public ApiClient ApiClient;
+ ///
+ /// Set the ApiClient using Default or ApiClient instance
+ ///
+ /// An instance of ApiClient
+ ///
+ public void setApiClientUsingDefault (ApiClient apiClient = null)
+ {
+ if (apiClient == null)
+ {
+ if (Default != null && Default.ApiClient == null)
+ Default.ApiClient = new ApiClient();
+
+ ApiClient = Default != null ? Default.ApiClient : new ApiClient();
+ }
+ else
+ {
+ if (Default != null && Default.ApiClient == null)
+ Default.ApiClient = apiClient;
+
+ ApiClient = apiClient;
+ }
+ }
+
private Dictionary _defaultHeaderMap = new Dictionary();
-
+
///
/// Gets or sets the default header.
///
@@ -134,13 +151,13 @@ namespace IO.Swagger.Client
///
/// The username.
public String Username { get; set; }
-
+
///
/// Gets or sets the password (HTTP basic authentication).
///
/// The password.
public String Password { get; set; }
-
+
///
/// Gets or sets the access token for OAuth2 authentication.
///
@@ -152,7 +169,7 @@ namespace IO.Swagger.Client
///
/// The API key.
public Dictionary ApiKey = new Dictionary();
-
+
///
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name.
///
@@ -174,9 +191,9 @@ namespace IO.Swagger.Client
else
return apiKeyValue;
}
-
+
private string _tempFolderPath = Path.GetTempPath();
-
+
///
/// Gets or sets the temporary folder path to store the files downloaded from the server.
///
@@ -184,19 +201,19 @@ namespace IO.Swagger.Client
public String TempFolderPath
{
get { return _tempFolderPath; }
-
- set
+
+ set
{
if (String.IsNullOrEmpty(value))
{
_tempFolderPath = value;
return;
}
-
+
// create the directory if it does not exist
if (!Directory.Exists(value))
Directory.CreateDirectory(value);
-
+
// check if the path contains directory separator at the end
if (value[value.Length - 1] == Path.DirectorySeparatorChar)
_tempFolderPath = value;
@@ -251,7 +268,7 @@ namespace IO.Swagger.Client
.Where(x => x.Name == "System.Core").First().Version.ToString() + "\n";
report += " Version of the API: 1.0.0\n";
report += " SDK Package Version: 1.0.0\n";
-
+
return report;
}
}
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs
index 4a3939f7094..1b32b6e5da6 100644
--- a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs
+++ b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs
@@ -1,29 +1,14 @@
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/TestApiClient.cs b/samples/client/petstore/csharp/SwaggerClientTest/TestApiClient.cs
index d57627a623a..af7c22ba088 100644
--- a/samples/client/petstore/csharp/SwaggerClientTest/TestApiClient.cs
+++ b/samples/client/petstore/csharp/SwaggerClientTest/TestApiClient.cs
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using IO.Swagger.Client;
+using IO.Swagger.Api;
namespace SwaggerClientTest.TestApiClient
{
@@ -111,6 +112,32 @@ namespace SwaggerClientTest.TestApiClient
Assert.AreEqual("sun.gif", ApiClient.SanitizeFilename(".\\sun.gif"));
}
+
+ [Test ()]
+ public void TestApiClientInstance ()
+ {
+ PetApi p1 = new PetApi ();
+ PetApi p2 = new PetApi ();
+
+ Configuration c1 = new Configuration (); // using default ApiClient
+ PetApi p3 = new PetApi (c1);
+
+ ApiClient a1 = new ApiClient();
+ Configuration c2 = new Configuration (a1); // using default ApiClient
+ PetApi p4 = new PetApi (c2);
+
+
+ // ensure both using the same default ApiClient
+ Assert.AreSame(p1.Configuration.ApiClient, p2.Configuration.ApiClient);
+ Assert.AreSame(p1.Configuration.ApiClient, Configuration.Default.ApiClient);
+
+ Assert.AreSame(p3.Configuration.ApiClient, c1.ApiClient);
+ Assert.AreSame(p3.Configuration.ApiClient, Configuration.Default.ApiClient);
+
+ Assert.AreSame(p4.Configuration.ApiClient, c2.ApiClient);
+ Assert.AreNotSame(p4.Configuration.ApiClient, Configuration.Default.ApiClient);
+
+ }
}
}
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
index 10b5d98d5fa..ad3f04827de 100755
Binary files a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll and b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll differ
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
index 292442f3a88..5008263b223 100644
Binary files a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb and b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb differ
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
index 10b5d98d5fa..ad3f04827de 100755
Binary files a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll and b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll differ