forked from loafle/openapi-generator-original
better auth for C#, format change
This commit is contained in:
parent
6712754f6a
commit
d5b80ac8cd
@ -198,10 +198,12 @@ namespace {{packageName}}.Client
|
||||
{
|
||||
if (obj is DateTime)
|
||||
return ((DateTime)obj).ToString ("u");
|
||||
else if (obj is IList) {
|
||||
else if (obj is IList)
|
||||
{
|
||||
string flattenString = "";
|
||||
string separator = ",";
|
||||
foreach (var param in (IList)obj) {
|
||||
foreach (var param in (IList)obj)
|
||||
{
|
||||
flattenString += param.ToString() + separator;
|
||||
}
|
||||
return flattenString.Remove(flattenString.Length - 1);;
|
||||
@ -318,11 +320,29 @@ namespace {{packageName}}.Client
|
||||
{
|
||||
{{#authMethods}}
|
||||
case "{{name}}":
|
||||
{{#isApiKey}}{{#isKeyInHeader}}headerParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInHeader}}{{#isKeyInQuery}}queryParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}headerParams["Authorization"] = "Basic " + Base64Encode(Configuration.Username + ":" + Configuration.Password);{{/isBasic}}{{#isOAuth}}headerParams["Authorization"] = "Bearer " + Configuration.AccessToken;{{/isOAuth}}
|
||||
{{#isApiKey}}{{#isKeyInHeader}}
|
||||
var apiKeyValue = GetApiKeyWithPrefix("{{keyParamName}}");
|
||||
if (!String.IsNullOrEmpty(apiKeyValue))
|
||||
{
|
||||
headerParams["{{keyParamName}}"] = apiKeyValue;
|
||||
}{{/isKeyInHeader}}{{#isKeyInQuery}}
|
||||
var apiKeyValue = GetApiKeyWithPrefix("{{keyParamName}}");
|
||||
if (!String.IsNullOrEmpty(apiKeyValue))
|
||||
{
|
||||
queryParams["{{keyParamName}}"] = apiKeyValue;
|
||||
}{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}
|
||||
if (!String.IsNullOrEmpty(Configuration.Username) && !String.IsNullOrEmpty(Configuration.Password))
|
||||
{
|
||||
headerParams["Authorization"] = "Basic " + Base64Encode(Configuration.Username + ":" + Configuration.Password);
|
||||
}{{/isBasic}}{{#isOAuth}}
|
||||
if (!String.IsNullOrEmpty(Configuration.AccessToken))
|
||||
{
|
||||
headerParams["Authorization"] = "Bearer " + Configuration.AccessToken;
|
||||
}{{/isOAuth}}
|
||||
break;
|
||||
{{/authMethods}}
|
||||
default:
|
||||
//TODO show warning about security definition not found
|
||||
//show warning about security definition not found
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -335,11 +355,14 @@ namespace {{packageName}}.Client
|
||||
/// </summary>
|
||||
/// <param name="accepts">The accepts array to select from.</param>
|
||||
/// <returns>The Accept header to use.</returns>
|
||||
public String SelectHeaderAccept(String[] accepts) {
|
||||
public String SelectHeaderAccept(String[] accepts)
|
||||
{
|
||||
if (accepts.Length == 0)
|
||||
return null;
|
||||
|
||||
if (accepts.Contains("application/json", StringComparer.OrdinalIgnoreCase))
|
||||
return "application/json";
|
||||
|
||||
return String.Join(",", accepts);
|
||||
}
|
||||
|
||||
@ -350,8 +373,7 @@ namespace {{packageName}}.Client
|
||||
/// <returns>Encoded string.</returns>
|
||||
public static string Base64Encode(string text)
|
||||
{
|
||||
var textByte = System.Text.Encoding.UTF8.GetBytes(text);
|
||||
return System.Convert.ToBase64String(textByte);
|
||||
return System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(text));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -361,7 +383,8 @@ namespace {{packageName}}.Client
|
||||
/// <param name="source">Object to be casted</param>
|
||||
/// <param name="dest">Target type</param>
|
||||
/// <returns>Casted object</returns>
|
||||
public static dynamic ConvertType(dynamic source, Type dest) {
|
||||
public static dynamic ConvertType(dynamic source, Type dest)
|
||||
{
|
||||
return Convert.ChangeType(source, dest);
|
||||
}
|
||||
|
||||
|
@ -198,10 +198,12 @@ namespace IO.Swagger.Client
|
||||
{
|
||||
if (obj is DateTime)
|
||||
return ((DateTime)obj).ToString ("u");
|
||||
else if (obj is IList) {
|
||||
else if (obj is IList)
|
||||
{
|
||||
string flattenString = "";
|
||||
string separator = ",";
|
||||
foreach (var param in (IList)obj) {
|
||||
foreach (var param in (IList)obj)
|
||||
{
|
||||
flattenString += param.ToString() + separator;
|
||||
}
|
||||
return flattenString.Remove(flattenString.Length - 1);;
|
||||
@ -318,15 +320,24 @@ namespace IO.Swagger.Client
|
||||
{
|
||||
|
||||
case "api_key":
|
||||
headerParams["api_key"] = GetApiKeyWithPrefix("api_key");
|
||||
|
||||
var apiKeyValue = GetApiKeyWithPrefix("api_key");
|
||||
if (!String.IsNullOrEmpty(apiKeyValue))
|
||||
{
|
||||
headerParams["api_key"] = apiKeyValue;
|
||||
}
|
||||
break;
|
||||
|
||||
case "petstore_auth":
|
||||
|
||||
if (!String.IsNullOrEmpty(Configuration.AccessToken))
|
||||
{
|
||||
headerParams["Authorization"] = "Bearer " + Configuration.AccessToken;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
//TODO show warning about security definition not found
|
||||
//show warning about security definition not found
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -339,11 +350,14 @@ namespace IO.Swagger.Client
|
||||
/// </summary>
|
||||
/// <param name="accepts">The accepts array to select from.</param>
|
||||
/// <returns>The Accept header to use.</returns>
|
||||
public String SelectHeaderAccept(String[] accepts) {
|
||||
public String SelectHeaderAccept(String[] accepts)
|
||||
{
|
||||
if (accepts.Length == 0)
|
||||
return null;
|
||||
|
||||
if (accepts.Contains("application/json", StringComparer.OrdinalIgnoreCase))
|
||||
return "application/json";
|
||||
|
||||
return String.Join(",", accepts);
|
||||
}
|
||||
|
||||
@ -354,8 +368,7 @@ namespace IO.Swagger.Client
|
||||
/// <returns>Encoded string.</returns>
|
||||
public static string Base64Encode(string text)
|
||||
{
|
||||
var textByte = System.Text.Encoding.UTF8.GetBytes(text);
|
||||
return System.Convert.ToBase64String(textByte);
|
||||
return System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(text));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -365,7 +378,8 @@ namespace IO.Swagger.Client
|
||||
/// <param name="source">Object to be casted</param>
|
||||
/// <param name="dest">Target type</param>
|
||||
/// <returns>Casted object</returns>
|
||||
public static dynamic ConvertType(dynamic source, Type dest) {
|
||||
public static dynamic ConvertType(dynamic source, Type dest)
|
||||
{
|
||||
return Convert.ChangeType(source, dest);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,12 @@
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
|
||||
/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/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/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/bin/Debug/Newtonsoft.Json.dll
|
||||
|
Loading…
x
Reference in New Issue
Block a user