forked from loafle/openapi-generator-original
remove some static methods in configuration
This commit is contained in:
@@ -19,7 +19,33 @@ namespace {{packageName}}.Client
|
||||
public class ApiClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiClient" /> class.
|
||||
/// Initializes a new instance of the <see cref="ApiClient" /> class
|
||||
/// with default configuration and base path ({{basePath}}).
|
||||
/// </summary>
|
||||
public ApiClient()
|
||||
{
|
||||
Configuration = Configuration.Default;
|
||||
RestClient = new RestClient("{{basePath}}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiClient" /> class
|
||||
/// with default base path ({{basePath}}).
|
||||
/// </summary>
|
||||
/// <param name="config">An instance of Configuration.</param>
|
||||
public ApiClient(Configuration config = null)
|
||||
{
|
||||
if (config == null)
|
||||
Configuration = Configuration.Default;
|
||||
else
|
||||
Configuration = config;
|
||||
|
||||
RestClient = new RestClient("{{basePath}}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiClient" /> class
|
||||
/// with default configuration.
|
||||
/// </summary>
|
||||
/// <param name="basePath">The base path.</param>
|
||||
public ApiClient(String basePath = "{{basePath}}")
|
||||
@@ -28,13 +54,20 @@ namespace {{packageName}}.Client
|
||||
throw new ArgumentException("basePath cannot be empty");
|
||||
|
||||
RestClient = new RestClient(basePath);
|
||||
Configuration = Configuration.Default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default API client for making HTTP calls.
|
||||
/// </summary>
|
||||
/// <value>The default API client.</value>
|
||||
public static ApiClient Default = new ApiClient();
|
||||
public static ApiClient Default = new ApiClient(Configuration.Default);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Configuration.
|
||||
/// </summary>
|
||||
/// <value>An instance of the Configuration.</value>
|
||||
public Configuration Configuration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the RestClient.
|
||||
|
||||
@@ -109,13 +109,13 @@ namespace {{packageName}}.Client
|
||||
return apiKeyValue;
|
||||
}
|
||||
|
||||
private static string _tempFolderPath = Path.GetTempPath();
|
||||
private string _tempFolderPath = Path.GetTempPath();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the temporary folder path to store the files downloaded from the server.
|
||||
/// </summary>
|
||||
/// <value>Folder path.</value>
|
||||
public static String TempFolderPath
|
||||
public String TempFolderPath
|
||||
{
|
||||
get { return _tempFolderPath; }
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace {{packageName}}.Client
|
||||
|
||||
private const string ISO8601_DATETIME_FORMAT = "o";
|
||||
|
||||
private static string _dateTimeFormat = ISO8601_DATETIME_FORMAT;
|
||||
private string _dateTimeFormat = ISO8601_DATETIME_FORMAT;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the the date time format used when serializing in the ApiClient
|
||||
@@ -151,7 +151,7 @@ namespace {{packageName}}.Client
|
||||
/// No validation is done to ensure that the string you're providing is valid
|
||||
/// </summary>
|
||||
/// <value>The DateTimeFormat string</value>
|
||||
public static String DateTimeFormat
|
||||
public String DateTimeFormat
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -6,7 +6,6 @@ using RestSharp;
|
||||
using IO.Swagger.Client;
|
||||
using IO.Swagger.Model;
|
||||
|
||||
|
||||
namespace IO.Swagger.Api
|
||||
{
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ using RestSharp;
|
||||
using IO.Swagger.Client;
|
||||
using IO.Swagger.Model;
|
||||
|
||||
|
||||
namespace IO.Swagger.Api
|
||||
{
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ using RestSharp;
|
||||
using IO.Swagger.Client;
|
||||
using IO.Swagger.Model;
|
||||
|
||||
|
||||
namespace IO.Swagger.Api
|
||||
{
|
||||
|
||||
|
||||
@@ -19,7 +19,33 @@ namespace IO.Swagger.Client
|
||||
public class ApiClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiClient" /> class.
|
||||
/// Initializes a new instance of the <see cref="ApiClient" /> class
|
||||
/// with default configuration and base path (http://petstore.swagger.io/v2).
|
||||
/// </summary>
|
||||
public ApiClient()
|
||||
{
|
||||
Configuration = Configuration.Default;
|
||||
RestClient = new RestClient("http://petstore.swagger.io/v2");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiClient" /> class
|
||||
/// with default base path (http://petstore.swagger.io/v2).
|
||||
/// </summary>
|
||||
/// <param name="config">An instance of Configuration.</param>
|
||||
public ApiClient(Configuration config = null)
|
||||
{
|
||||
if (config == null)
|
||||
Configuration = Configuration.Default;
|
||||
else
|
||||
Configuration = config;
|
||||
|
||||
RestClient = new RestClient("http://petstore.swagger.io/v2");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiClient" /> class
|
||||
/// with default configuration.
|
||||
/// </summary>
|
||||
/// <param name="basePath">The base path.</param>
|
||||
public ApiClient(String basePath = "http://petstore.swagger.io/v2")
|
||||
@@ -28,13 +54,20 @@ namespace IO.Swagger.Client
|
||||
throw new ArgumentException("basePath cannot be empty");
|
||||
|
||||
RestClient = new RestClient(basePath);
|
||||
Configuration = Configuration.Default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default API client for making HTTP calls.
|
||||
/// </summary>
|
||||
/// <value>The default API client.</value>
|
||||
public static ApiClient Default = new ApiClient();
|
||||
public static ApiClient Default = new ApiClient(Configuration.Default);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Configuration.
|
||||
/// </summary>
|
||||
/// <value>An instance of the Configuration.</value>
|
||||
public Configuration Configuration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the RestClient.
|
||||
|
||||
@@ -109,13 +109,13 @@ namespace IO.Swagger.Client
|
||||
return apiKeyValue;
|
||||
}
|
||||
|
||||
private static string _tempFolderPath = Path.GetTempPath();
|
||||
private string _tempFolderPath = Path.GetTempPath();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the temporary folder path to store the files downloaded from the server.
|
||||
/// </summary>
|
||||
/// <value>Folder path.</value>
|
||||
public static String TempFolderPath
|
||||
public String TempFolderPath
|
||||
{
|
||||
get { return _tempFolderPath; }
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace IO.Swagger.Client
|
||||
|
||||
private const string ISO8601_DATETIME_FORMAT = "o";
|
||||
|
||||
private static string _dateTimeFormat = ISO8601_DATETIME_FORMAT;
|
||||
private string _dateTimeFormat = ISO8601_DATETIME_FORMAT;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the the date time format used when serializing in the ApiClient
|
||||
@@ -151,7 +151,7 @@ namespace IO.Swagger.Client
|
||||
/// No validation is done to ensure that the string you're providing is valid
|
||||
/// </summary>
|
||||
/// <value>The DateTimeFormat string</value>
|
||||
public static String DateTimeFormat
|
||||
public String DateTimeFormat
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -7,8 +7,6 @@ using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
||||
|
||||
namespace IO.Swagger.Model
|
||||
{
|
||||
|
||||
@@ -124,6 +122,4 @@ namespace IO.Swagger.Model
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
||||
|
||||
namespace IO.Swagger.Model
|
||||
{
|
||||
|
||||
@@ -189,6 +187,4 @@ namespace IO.Swagger.Model
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
||||
|
||||
namespace IO.Swagger.Model
|
||||
{
|
||||
|
||||
@@ -189,6 +187,4 @@ namespace IO.Swagger.Model
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
||||
|
||||
namespace IO.Swagger.Model
|
||||
{
|
||||
|
||||
@@ -124,6 +122,4 @@ namespace IO.Swagger.Model
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
||||
|
||||
namespace IO.Swagger.Model
|
||||
{
|
||||
|
||||
@@ -221,6 +219,4 @@ namespace IO.Swagger.Model
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace SwaggerClientTest.TestApiClient
|
||||
public void TearDown()
|
||||
{
|
||||
// Reset to default, just in case
|
||||
Configuration.DateTimeFormat = "o";
|
||||
Configuration.Default.DateTimeFormat = "o";
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
@@ -29,7 +29,7 @@ namespace SwaggerClientTest.TestApiClient
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestParameterToString_DateTime ()
|
||||
public void TestParameterToStringForDateTime ()
|
||||
{
|
||||
ApiClient api = new ApiClient ();
|
||||
|
||||
@@ -40,17 +40,23 @@ namespace SwaggerClientTest.TestApiClient
|
||||
// test datetime with no timezone
|
||||
DateTime dateWithNoTz = DateTime.Parse ("2008-04-10T13:30:00.000", null, System.Globalization.DateTimeStyles.RoundtripKind);
|
||||
Assert.AreEqual ("2008-04-10T13:30:00.0000000", api.ParameterToString (dateWithNoTz));
|
||||
}
|
||||
|
||||
// The test below only passes when running at -04:00 timezone
|
||||
[Ignore ()]
|
||||
public void TestParameterToStringWithTimeZoneForDateTime ()
|
||||
{
|
||||
ApiClient api = new ApiClient ();
|
||||
// test datetime with a time zone
|
||||
DateTime dateWithTz = DateTime.Parse("2008-04-10T13:30:00.0000000-04:00", null, System.Globalization.DateTimeStyles.RoundtripKind);
|
||||
Assert.AreEqual("2008-04-10T13:30:00.0000000-04:00", api.ParameterToString(dateWithTz));
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestParameterToString_DateTime_WithUFormat ()
|
||||
public void TestParameterToStringForDateTimeWithUFormat ()
|
||||
{
|
||||
// Setup the DateTimeFormat across all of the calls
|
||||
Configuration.DateTimeFormat = "u";
|
||||
Configuration.Default.DateTimeFormat = "u";
|
||||
ApiClient api = new ApiClient();
|
||||
|
||||
// test datetime
|
||||
@@ -59,10 +65,10 @@ namespace SwaggerClientTest.TestApiClient
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestParameterToString_DateTime_WithCustomFormat ()
|
||||
public void TestParameterToStringForDateTimeWithCustomFormat ()
|
||||
{
|
||||
// Setup the DateTimeFormat across all of the calls
|
||||
Configuration.DateTimeFormat = "dd/MM/yy HH:mm:ss";
|
||||
Configuration.Default.DateTimeFormat = "dd/MM/yy HH:mm:ss";
|
||||
ApiClient api = new ApiClient();
|
||||
|
||||
// test datetime
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace SwaggerClientTest.TestConfiguration
|
||||
public void TearDown ()
|
||||
{
|
||||
// Reset to default, just in case
|
||||
Configuration.DateTimeFormat = "o";
|
||||
Configuration.Default.DateTimeFormat = "o";
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
@@ -44,15 +44,15 @@ namespace SwaggerClientTest.TestConfiguration
|
||||
{
|
||||
// Should default to the Round-trip Format Specifier - "o"
|
||||
// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8
|
||||
Assert.AreEqual("o", Configuration.DateTimeFormat);
|
||||
Assert.AreEqual("o", Configuration.Default.DateTimeFormat);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestDateTimeFormat_UType()
|
||||
{
|
||||
Configuration.DateTimeFormat = "u";
|
||||
Configuration.Default.DateTimeFormat = "u";
|
||||
|
||||
Assert.AreEqual("u", Configuration.DateTimeFormat);
|
||||
Assert.AreEqual("u", Configuration.Default.DateTimeFormat);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,5 @@
|
||||
/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/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
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user