forked from loafle/openapi-generator-original
update csharp configuration to avoid circular dependency, deprecate
ApiClient.Default
This commit is contained in:
parent
e2f646039c
commit
417dcc8a86
@ -61,7 +61,8 @@ namespace {{packageName}}.Client
|
||||
/// Gets or sets the default API client for making HTTP calls.
|
||||
/// </summary>
|
||||
/// <value>The default API client.</value>
|
||||
public static ApiClient Default = new ApiClient(Configuration.Default);
|
||||
[Obsolete("ApiClient.Default is deprecated, please use 'Configuraiton.Default.ApiClient' instead.")]
|
||||
public static ApiClient Default;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Configuration.
|
||||
|
@ -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
|
||||
/// <param name="apiClient">Api client.</param>
|
||||
public Configuration(ApiClient apiClient)
|
||||
{
|
||||
if (apiClient == null)
|
||||
ApiClient = ApiClient.Default;
|
||||
else
|
||||
ApiClient = apiClient;
|
||||
setApiClientUsingDefault(apiClient);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Version of the package.
|
||||
/// </summary>
|
||||
/// <value>Version of the package.</value>
|
||||
public const string Version = "{{packageVersion}}";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default Configuration.
|
||||
/// </summary>
|
||||
@ -103,8 +97,31 @@ namespace {{packageName}}.Client
|
||||
/// <value>The API client.</value>
|
||||
public ApiClient ApiClient;
|
||||
|
||||
/// <summary>
|
||||
/// Set the ApiClient using Default or ApiClient instance
|
||||
/// </summary>
|
||||
/// <param name="apiClient">An instance of ApiClient
|
||||
/// <returns></returns>
|
||||
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<String, String> _defaultHeaderMap = new Dictionary<String, String>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default header.
|
||||
/// </summary>
|
||||
@ -134,13 +151,13 @@ namespace {{packageName}}.Client
|
||||
/// </summary>
|
||||
/// <value>The username.</value>
|
||||
public String Username { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the password (HTTP basic authentication).
|
||||
/// </summary>
|
||||
/// <value>The password.</value>
|
||||
public String Password { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the access token for OAuth2 authentication.
|
||||
/// </summary>
|
||||
@ -152,7 +169,7 @@ namespace {{packageName}}.Client
|
||||
/// </summary>
|
||||
/// <value>The API key.</value>
|
||||
public Dictionary<String, String> ApiKey = new Dictionary<String, String>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name.
|
||||
/// </summary>
|
||||
@ -174,9 +191,9 @@ namespace {{packageName}}.Client
|
||||
else
|
||||
return apiKeyValue;
|
||||
}
|
||||
|
||||
|
||||
private string _tempFolderPath = Path.GetTempPath();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the temporary folder path to store the files downloaded from the server.
|
||||
/// </summary>
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,8 @@ namespace IO.Swagger.Client
|
||||
/// Gets or sets the default API client for making HTTP calls.
|
||||
/// </summary>
|
||||
/// <value>The default API client.</value>
|
||||
public static ApiClient Default = new ApiClient(Configuration.Default);
|
||||
[Obsolete("ApiClient.Default is deprecated, please use 'Configuraiton.Default.ApiClient' instead.")]
|
||||
public static ApiClient Default;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Configuration.
|
||||
|
@ -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
|
||||
/// <param name="apiClient">Api client.</param>
|
||||
public Configuration(ApiClient apiClient)
|
||||
{
|
||||
if (apiClient == null)
|
||||
ApiClient = ApiClient.Default;
|
||||
else
|
||||
ApiClient = apiClient;
|
||||
setApiClientUsingDefault(apiClient);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Version of the package.
|
||||
/// </summary>
|
||||
/// <value>Version of the package.</value>
|
||||
public const string Version = "1.0.0";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default Configuration.
|
||||
/// </summary>
|
||||
@ -103,8 +97,31 @@ namespace IO.Swagger.Client
|
||||
/// <value>The API client.</value>
|
||||
public ApiClient ApiClient;
|
||||
|
||||
/// <summary>
|
||||
/// Set the ApiClient using Default or ApiClient instance
|
||||
/// </summary>
|
||||
/// <param name="apiClient">An instance of ApiClient
|
||||
/// <returns></returns>
|
||||
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<String, String> _defaultHeaderMap = new Dictionary<String, String>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default header.
|
||||
/// </summary>
|
||||
@ -134,13 +151,13 @@ namespace IO.Swagger.Client
|
||||
/// </summary>
|
||||
/// <value>The username.</value>
|
||||
public String Username { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the password (HTTP basic authentication).
|
||||
/// </summary>
|
||||
/// <value>The password.</value>
|
||||
public String Password { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the access token for OAuth2 authentication.
|
||||
/// </summary>
|
||||
@ -152,7 +169,7 @@ namespace IO.Swagger.Client
|
||||
/// </summary>
|
||||
/// <value>The API key.</value>
|
||||
public Dictionary<String, String> ApiKey = new Dictionary<String, String>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name.
|
||||
/// </summary>
|
||||
@ -174,9 +191,9 @@ namespace IO.Swagger.Client
|
||||
else
|
||||
return apiKeyValue;
|
||||
}
|
||||
|
||||
|
||||
private string _tempFolderPath = Path.GetTempPath();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the temporary folder path to store the files downloaded from the server.
|
||||
/// </summary>
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,14 @@
|
||||
<Properties StartupItem="SwaggerClientTest.csproj">
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs">
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="TestApiClient.cs">
|
||||
<Files>
|
||||
<File FileName="TestPet.cs" Line="182" Column="4" />
|
||||
<File FileName="TestPet.cs" Line="1" Column="1" />
|
||||
<File FileName="TestConfiguration.cs" Line="1" Column="1" />
|
||||
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs" Line="1" Column="1" />
|
||||
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs" Line="1" Column="1" />
|
||||
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs" Line="64" Column="50" />
|
||||
<File FileName="TestApiClient.cs" Line="1" Column="1" />
|
||||
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs" Line="1" Column="1" />
|
||||
</Files>
|
||||
<Pads>
|
||||
<Pad Id="MonoDevelop.NUnit.TestPad">
|
||||
<State name="__root__">
|
||||
<Node name="SwaggerClientTest" expanded="True">
|
||||
<Node name="SwaggerClientTest" expanded="True">
|
||||
<Node name="SwaggerClientTest" expanded="True">
|
||||
<Node name="TestApiClient" expanded="True">
|
||||
<Node name="TestApiClient" expanded="True" />
|
||||
</Node>
|
||||
</Node>
|
||||
</Node>
|
||||
</Node>
|
||||
</State>
|
||||
</Pad>
|
||||
</Pads>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<BreakpointStore />
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user