mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-05 15:10:49 +00:00
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.
|
/// Gets or sets the default API client for making HTTP calls.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The default API client.</value>
|
/// <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>
|
/// <summary>
|
||||||
/// Gets or sets the Configuration.
|
/// Gets or sets the Configuration.
|
||||||
|
@ -37,10 +37,7 @@ namespace {{packageName}}.Client
|
|||||||
int timeout = 100000
|
int timeout = 100000
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (apiClient == null)
|
setApiClientUsingDefault(apiClient);
|
||||||
ApiClient = ApiClient.Default == null ? new ApiClient() : ApiClient.Default;
|
|
||||||
else
|
|
||||||
ApiClient = apiClient;
|
|
||||||
|
|
||||||
Username = username;
|
Username = username;
|
||||||
Password = password;
|
Password = password;
|
||||||
@ -64,18 +61,15 @@ namespace {{packageName}}.Client
|
|||||||
/// <param name="apiClient">Api client.</param>
|
/// <param name="apiClient">Api client.</param>
|
||||||
public Configuration(ApiClient apiClient)
|
public Configuration(ApiClient apiClient)
|
||||||
{
|
{
|
||||||
if (apiClient == null)
|
setApiClientUsingDefault(apiClient);
|
||||||
ApiClient = ApiClient.Default;
|
|
||||||
else
|
|
||||||
ApiClient = apiClient;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Version of the package.
|
/// Version of the package.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>Version of the package.</value>
|
/// <value>Version of the package.</value>
|
||||||
public const string Version = "{{packageVersion}}";
|
public const string Version = "{{packageVersion}}";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the default Configuration.
|
/// Gets or sets the default Configuration.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -103,8 +97,31 @@ namespace {{packageName}}.Client
|
|||||||
/// <value>The API client.</value>
|
/// <value>The API client.</value>
|
||||||
public ApiClient ApiClient;
|
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>();
|
private Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the default header.
|
/// Gets or sets the default header.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -134,13 +151,13 @@ namespace {{packageName}}.Client
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The username.</value>
|
/// <value>The username.</value>
|
||||||
public String Username { get; set; }
|
public String Username { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the password (HTTP basic authentication).
|
/// Gets or sets the password (HTTP basic authentication).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The password.</value>
|
/// <value>The password.</value>
|
||||||
public String Password { get; set; }
|
public String Password { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the access token for OAuth2 authentication.
|
/// Gets or sets the access token for OAuth2 authentication.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -152,7 +169,7 @@ namespace {{packageName}}.Client
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The API key.</value>
|
/// <value>The API key.</value>
|
||||||
public Dictionary<String, String> ApiKey = new Dictionary<String, String>();
|
public Dictionary<String, String> ApiKey = new Dictionary<String, String>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name.
|
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -174,9 +191,9 @@ namespace {{packageName}}.Client
|
|||||||
else
|
else
|
||||||
return apiKeyValue;
|
return apiKeyValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string _tempFolderPath = Path.GetTempPath();
|
private string _tempFolderPath = Path.GetTempPath();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the temporary folder path to store the files downloaded from the server.
|
/// Gets or sets the temporary folder path to store the files downloaded from the server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -184,19 +201,19 @@ namespace {{packageName}}.Client
|
|||||||
public String TempFolderPath
|
public String TempFolderPath
|
||||||
{
|
{
|
||||||
get { return _tempFolderPath; }
|
get { return _tempFolderPath; }
|
||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (String.IsNullOrEmpty(value))
|
if (String.IsNullOrEmpty(value))
|
||||||
{
|
{
|
||||||
_tempFolderPath = value;
|
_tempFolderPath = value;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the directory if it does not exist
|
// create the directory if it does not exist
|
||||||
if (!Directory.Exists(value))
|
if (!Directory.Exists(value))
|
||||||
Directory.CreateDirectory(value);
|
Directory.CreateDirectory(value);
|
||||||
|
|
||||||
// check if the path contains directory separator at the end
|
// check if the path contains directory separator at the end
|
||||||
if (value[value.Length - 1] == Path.DirectorySeparatorChar)
|
if (value[value.Length - 1] == Path.DirectorySeparatorChar)
|
||||||
_tempFolderPath = value;
|
_tempFolderPath = value;
|
||||||
@ -251,7 +268,7 @@ namespace {{packageName}}.Client
|
|||||||
.Where(x => x.Name == "System.Core").First().Version.ToString() + "\n";
|
.Where(x => x.Name == "System.Core").First().Version.ToString() + "\n";
|
||||||
report += " Version of the API: {{version}}\n";
|
report += " Version of the API: {{version}}\n";
|
||||||
report += " SDK Package Version: {{packageVersion}}\n";
|
report += " SDK Package Version: {{packageVersion}}\n";
|
||||||
|
|
||||||
return report;
|
return report;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,8 @@ namespace IO.Swagger.Client
|
|||||||
/// 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 default API client.</value>
|
/// <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>
|
/// <summary>
|
||||||
/// Gets or sets the Configuration.
|
/// Gets or sets the Configuration.
|
||||||
|
@ -37,10 +37,7 @@ namespace IO.Swagger.Client
|
|||||||
int timeout = 100000
|
int timeout = 100000
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (apiClient == null)
|
setApiClientUsingDefault(apiClient);
|
||||||
ApiClient = ApiClient.Default == null ? new ApiClient() : ApiClient.Default;
|
|
||||||
else
|
|
||||||
ApiClient = apiClient;
|
|
||||||
|
|
||||||
Username = username;
|
Username = username;
|
||||||
Password = password;
|
Password = password;
|
||||||
@ -64,18 +61,15 @@ namespace IO.Swagger.Client
|
|||||||
/// <param name="apiClient">Api client.</param>
|
/// <param name="apiClient">Api client.</param>
|
||||||
public Configuration(ApiClient apiClient)
|
public Configuration(ApiClient apiClient)
|
||||||
{
|
{
|
||||||
if (apiClient == null)
|
setApiClientUsingDefault(apiClient);
|
||||||
ApiClient = ApiClient.Default;
|
|
||||||
else
|
|
||||||
ApiClient = apiClient;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Version of the package.
|
/// Version of the package.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>Version of the package.</value>
|
/// <value>Version of the package.</value>
|
||||||
public const string Version = "1.0.0";
|
public const string Version = "1.0.0";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the default Configuration.
|
/// Gets or sets the default Configuration.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -103,8 +97,31 @@ namespace IO.Swagger.Client
|
|||||||
/// <value>The API client.</value>
|
/// <value>The API client.</value>
|
||||||
public ApiClient ApiClient;
|
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>();
|
private Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the default header.
|
/// Gets or sets the default header.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -134,13 +151,13 @@ namespace IO.Swagger.Client
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The username.</value>
|
/// <value>The username.</value>
|
||||||
public String Username { get; set; }
|
public String Username { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the password (HTTP basic authentication).
|
/// Gets or sets the password (HTTP basic authentication).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The password.</value>
|
/// <value>The password.</value>
|
||||||
public String Password { get; set; }
|
public String Password { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the access token for OAuth2 authentication.
|
/// Gets or sets the access token for OAuth2 authentication.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -152,7 +169,7 @@ namespace IO.Swagger.Client
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The API key.</value>
|
/// <value>The API key.</value>
|
||||||
public Dictionary<String, String> ApiKey = new Dictionary<String, String>();
|
public Dictionary<String, String> ApiKey = new Dictionary<String, String>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name.
|
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -174,9 +191,9 @@ namespace IO.Swagger.Client
|
|||||||
else
|
else
|
||||||
return apiKeyValue;
|
return apiKeyValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string _tempFolderPath = Path.GetTempPath();
|
private string _tempFolderPath = Path.GetTempPath();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the temporary folder path to store the files downloaded from the server.
|
/// Gets or sets the temporary folder path to store the files downloaded from the server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -184,19 +201,19 @@ namespace IO.Swagger.Client
|
|||||||
public String TempFolderPath
|
public String TempFolderPath
|
||||||
{
|
{
|
||||||
get { return _tempFolderPath; }
|
get { return _tempFolderPath; }
|
||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (String.IsNullOrEmpty(value))
|
if (String.IsNullOrEmpty(value))
|
||||||
{
|
{
|
||||||
_tempFolderPath = value;
|
_tempFolderPath = value;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the directory if it does not exist
|
// create the directory if it does not exist
|
||||||
if (!Directory.Exists(value))
|
if (!Directory.Exists(value))
|
||||||
Directory.CreateDirectory(value);
|
Directory.CreateDirectory(value);
|
||||||
|
|
||||||
// check if the path contains directory separator at the end
|
// check if the path contains directory separator at the end
|
||||||
if (value[value.Length - 1] == Path.DirectorySeparatorChar)
|
if (value[value.Length - 1] == Path.DirectorySeparatorChar)
|
||||||
_tempFolderPath = value;
|
_tempFolderPath = value;
|
||||||
@ -251,7 +268,7 @@ namespace IO.Swagger.Client
|
|||||||
.Where(x => x.Name == "System.Core").First().Version.ToString() + "\n";
|
.Where(x => x.Name == "System.Core").First().Version.ToString() + "\n";
|
||||||
report += " Version of the API: 1.0.0\n";
|
report += " Version of the API: 1.0.0\n";
|
||||||
report += " SDK Package Version: 1.0.0\n";
|
report += " SDK Package Version: 1.0.0\n";
|
||||||
|
|
||||||
return report;
|
return report;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,14 @@
|
|||||||
<Properties StartupItem="SwaggerClientTest.csproj">
|
<Properties StartupItem="SwaggerClientTest.csproj">
|
||||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
|
<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>
|
<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="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/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="TestApiClient.cs" Line="1" Column="1" />
|
||||||
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs" Line="1" Column="1" />
|
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs" Line="1" Column="1" />
|
||||||
</Files>
|
</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.Workbench>
|
||||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||||
<BreakpointStore />
|
<BreakpointStore />
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using IO.Swagger.Client;
|
using IO.Swagger.Client;
|
||||||
|
using IO.Swagger.Api;
|
||||||
|
|
||||||
namespace SwaggerClientTest.TestApiClient
|
namespace SwaggerClientTest.TestApiClient
|
||||||
{
|
{
|
||||||
@ -111,6 +112,32 @@ namespace SwaggerClientTest.TestApiClient
|
|||||||
Assert.AreEqual("sun.gif", ApiClient.SanitizeFilename(".\\sun.gif"));
|
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