Skip to content

Commit

Permalink
[c-sharp] generator added CancellationToken to async api calls (#6243)
Browse files Browse the repository at this point in the history
* csharp generator CancellationToken added to async methods

* update samples
  • Loading branch information
kilimnik authored May 11, 2020
1 parent 57c986f commit 5693cb9
Show file tree
Hide file tree
Showing 503 changed files with 28,043 additions and 6,896 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Reflection;

[assembly: System.Reflection.AssemblyCompanyAttribute("Org.OpenAPITools.Test")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("Org.OpenAPITools.Test")]
[assembly: System.Reflection.AssemblyTitleAttribute("Org.OpenAPITools.Test")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

// Generated by the MSBuild WriteCodeFragment class.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
19e887ae0fddb9fd03c4341951ee9077703a652f
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Reflection;

[assembly: System.Reflection.AssemblyCompanyAttribute("Org.OpenAPITools.Test")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("Org.OpenAPITools.Test")]
[assembly: System.Reflection.AssemblyTitleAttribute("Org.OpenAPITools.Test")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

// Generated by the MSBuild WriteCodeFragment class.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
19e887ae0fddb9fd03c4341951ee9077703a652f
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;
using System.IO;
using System.Threading;
{{^netStandard}}
{{^supportsUWP}}
using System.Web;
Expand Down Expand Up @@ -235,19 +236,20 @@ namespace {{packageName}}.Client
/// <param name="fileParams">File parameters.</param>
/// <param name="pathParams">Path parameters.</param>
/// <param name="contentType">Content type.</param>
/// <param name="cancellationToken">Cancellation Token.</param>
/// <returns>The Task instance.</returns>
public async System.Threading.Tasks.Task<Object> CallApiAsync(
String path, {{^netStandard}}RestSharp.{{/netStandard}}Method method, List<KeyValuePair<String, String>> queryParams, Object postBody,
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams,
String contentType)
String contentType, CancellationToken cancellationToken)
{
var request = PrepareRequest(
path, method, queryParams, postBody, headerParams, formParams, fileParams,
pathParams, contentType);
RestClient.UserAgent = Configuration.UserAgent;
InterceptRequest(request);
var response = await RestClient.Execute{{^netStandard}}TaskAsync{{/netStandard}}(request);
var response = await RestClient.Execute{{^netStandard}}TaskAsync{{/netStandard}}(request, cancellationToken);
InterceptResponse(request, response);
return (Object)response;
}{{/supportsAsync}}
Expand Down
27 changes: 16 additions & 11 deletions modules/openapi-generator/src/main/resources/csharp/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
{{#netStandard}}
using RestSharp.Portable;
{{/netStandard}}
Expand Down Expand Up @@ -57,8 +58,9 @@ namespace {{packageName}}.{{apiPackage}}
/// </remarks>
/// <exception cref="{{packageName}}.Client.ApiException">Thrown when fails to make API call</exception>
{{#allParams}}/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>
{{/allParams}}/// <returns>Task of {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}void{{/returnType}}</returns>
{{#returnType}}System.Threading.Tasks.Task<{{{returnType}}}>{{/returnType}}{{^returnType}}System.Threading.Tasks.Task{{/returnType}} {{operationId}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default({{{dataType}}}){{/optionalMethodArgument}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
{{/allParams}}/// <param name="cancellationToken">Cancellation Token to cancel request (optional) </param>
/// <returns>Task of {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}void{{/returnType}}</returns>
{{#returnType}}System.Threading.Tasks.Task<{{{returnType}}}>{{/returnType}}{{^returnType}}System.Threading.Tasks.Task{{/returnType}} {{operationId}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default({{{dataType}}}){{/optionalMethodArgument}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// {{summary}}
Expand All @@ -68,8 +70,9 @@ namespace {{packageName}}.{{apiPackage}}
/// </remarks>
/// <exception cref="{{packageName}}.Client.ApiException">Thrown when fails to make API call</exception>
{{#allParams}}/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>
{{/allParams}}/// <returns>Task of ApiResponse{{#returnType}} ({{returnType}}){{/returnType}}</returns>
System.Threading.Tasks.Task<ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}>> {{operationId}}AsyncWithHttpInfo ({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default({{{dataType}}}){{/optionalMethodArgument}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
{{/allParams}}/// <param name="cancellationToken">Cancellation Token to cancel request (optional) </param>
/// <returns>Task of ApiResponse{{#returnType}} ({{returnType}}){{/returnType}}</returns>
System.Threading.Tasks.Task<ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}>> {{operationId}}AsyncWithHttpInfo ({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default({{{dataType}}}){{/optionalMethodArgument}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}CancellationToken cancellationToken = default(CancellationToken));
{{/operation}}
#endregion Asynchronous Operations
{{/supportsAsync}}
Expand Down Expand Up @@ -333,11 +336,12 @@ namespace {{packageName}}.{{apiPackage}}
/// </summary>
/// <exception cref="{{packageName}}.Client.ApiException">Thrown when fails to make API call</exception>
{{#allParams}}/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>
{{/allParams}}/// <returns>Task of {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}void{{/returnType}}</returns>
{{#returnType}}public async System.Threading.Tasks.Task<{{{returnType}}}>{{/returnType}}{{^returnType}}public async System.Threading.Tasks.Task{{/returnType}} {{operationId}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default({{{dataType}}}){{/optionalMethodArgument}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
{{/allParams}}/// <param name="cancellationToken">Cancellation Token to cancel request (optional) </param>
/// <returns>Task of {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}void{{/returnType}}</returns>
{{#returnType}}public async System.Threading.Tasks.Task<{{{returnType}}}>{{/returnType}}{{^returnType}}public async System.Threading.Tasks.Task{{/returnType}} {{operationId}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default({{{dataType}}}){{/optionalMethodArgument}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}CancellationToken cancellationToken = default(CancellationToken))
{
{{#returnType}}ApiResponse<{{{returnType}}}> localVarResponse = await {{operationId}}AsyncWithHttpInfo({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
return localVarResponse.Data;{{/returnType}}{{^returnType}}await {{operationId}}AsyncWithHttpInfo({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{/returnType}}
{{#returnType}}ApiResponse<{{{returnType}}}> localVarResponse = await {{operationId}}AsyncWithHttpInfo({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}cancellationToken);
return localVarResponse.Data;{{/returnType}}{{^returnType}}await {{operationId}}AsyncWithHttpInfo({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}cancellationToken);{{/returnType}}

}

Expand All @@ -346,8 +350,9 @@ namespace {{packageName}}.{{apiPackage}}
/// </summary>
/// <exception cref="{{packageName}}.Client.ApiException">Thrown when fails to make API call</exception>
{{#allParams}}/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>
{{/allParams}}/// <returns>Task of ApiResponse{{#returnType}} ({{returnType}}){{/returnType}}</returns>
public async System.Threading.Tasks.Task<ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}>> {{operationId}}AsyncWithHttpInfo ({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default({{{dataType}}}){{/optionalMethodArgument}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
{{/allParams}}/// <param name="cancellationToken">Cancellation Token to cancel request (optional) </param>
/// <returns>Task of ApiResponse{{#returnType}} ({{returnType}}){{/returnType}}</returns>
public async System.Threading.Tasks.Task<ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}>> {{operationId}}AsyncWithHttpInfo ({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default({{{dataType}}}){{/optionalMethodArgument}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}CancellationToken cancellationToken = default(CancellationToken))
{
{{#allParams}}
{{#required}}
Expand Down Expand Up @@ -450,7 +455,7 @@ namespace {{packageName}}.{{apiPackage}}
// make the HTTP request
IRestResponse localVarResponse = (IRestResponse) await this.Configuration.ApiClient.CallApiAsync(localVarPath,
Method.{{httpMethod}}, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
localVarPathParams, localVarHttpContentType);
localVarPathParams, localVarHttpContentType, cancellationToken);

int localVarStatusCode = (int) localVarResponse.StatusCode;

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.3.1-SNAPSHOT
5.0.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,3 @@
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

src/Org.OpenAPITools.Test/Org.OpenAPITools.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
* The version of the OpenAPI document: 1.0.0
*
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
Expand Down Expand Up @@ -58,8 +58,8 @@ public void Cleanup()
[Test]
public void InstanceTest()
{
// TODO uncomment below to test 'IsInstanceOfType' AnotherFakeApi
//Assert.IsInstanceOfType(typeof(AnotherFakeApi), instance, "instance is a AnotherFakeApi");
// TODO uncomment below to test 'IsInstanceOf' AnotherFakeApi
//Assert.IsInstanceOf(typeof(AnotherFakeApi), instance);
}


Expand All @@ -72,7 +72,7 @@ public void Call123TestSpecialTagsTest()
// TODO uncomment below to test the method and replace null with proper value
//ModelClient body = null;
//var response = instance.Call123TestSpecialTags(body);
//Assert.IsInstanceOf<ModelClient> (response, "response is ModelClient");
//Assert.IsInstanceOf(typeof(ModelClient), response, "response is ModelClient");
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
* The version of the OpenAPI document: 1.0.0
*
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
Expand Down Expand Up @@ -58,8 +58,8 @@ public void Cleanup()
[Test]
public void InstanceTest()
{
// TODO uncomment below to test 'IsInstanceOfType' FakeApi
//Assert.IsInstanceOfType(typeof(FakeApi), instance, "instance is a FakeApi");
// TODO uncomment below to test 'IsInstanceOf' FakeApi
//Assert.IsInstanceOf(typeof(FakeApi), instance);
}


Expand All @@ -84,7 +84,7 @@ public void FakeOuterBooleanSerializeTest()
// TODO uncomment below to test the method and replace null with proper value
//bool? body = null;
//var response = instance.FakeOuterBooleanSerialize(body);
//Assert.IsInstanceOf<bool?> (response, "response is bool?");
//Assert.IsInstanceOf(typeof(bool), response, "response is bool");
}

/// <summary>
Expand All @@ -96,7 +96,7 @@ public void FakeOuterCompositeSerializeTest()
// TODO uncomment below to test the method and replace null with proper value
//OuterComposite body = null;
//var response = instance.FakeOuterCompositeSerialize(body);
//Assert.IsInstanceOf<OuterComposite> (response, "response is OuterComposite");
//Assert.IsInstanceOf(typeof(OuterComposite), response, "response is OuterComposite");
}

/// <summary>
Expand All @@ -108,7 +108,7 @@ public void FakeOuterNumberSerializeTest()
// TODO uncomment below to test the method and replace null with proper value
//decimal? body = null;
//var response = instance.FakeOuterNumberSerialize(body);
//Assert.IsInstanceOf<decimal?> (response, "response is decimal?");
//Assert.IsInstanceOf(typeof(decimal), response, "response is decimal");
}

/// <summary>
Expand All @@ -120,7 +120,7 @@ public void FakeOuterStringSerializeTest()
// TODO uncomment below to test the method and replace null with proper value
//string body = null;
//var response = instance.FakeOuterStringSerialize(body);
//Assert.IsInstanceOf<string> (response, "response is string");
//Assert.IsInstanceOf(typeof(string), response, "response is string");
}

/// <summary>
Expand Down Expand Up @@ -157,7 +157,7 @@ public void TestClientModelTest()
// TODO uncomment below to test the method and replace null with proper value
//ModelClient body = null;
//var response = instance.TestClientModel(body);
//Assert.IsInstanceOf<ModelClient> (response, "response is ModelClient");
//Assert.IsInstanceOf(typeof(ModelClient), response, "response is ModelClient");
}

/// <summary>
Expand All @@ -167,8 +167,8 @@ public void TestClientModelTest()
public void TestEndpointParametersTest()
{
// TODO uncomment below to test the method and replace null with proper value
//decimal? number = null;
//double? _double = null;
//decimal number = null;
//double _double = null;
//string patternWithoutDelimiter = null;
//byte[] _byte = null;
//int? integer = null;
Expand Down Expand Up @@ -211,9 +211,9 @@ public void TestEnumParametersTest()
public void TestGroupParametersTest()
{
// TODO uncomment below to test the method and replace null with proper value
//int? requiredStringGroup = null;
//bool? requiredBooleanGroup = null;
//long? requiredInt64Group = null;
//int requiredStringGroup = null;
//bool requiredBooleanGroup = null;
//long requiredInt64Group = null;
//int? stringGroup = null;
//bool? booleanGroup = null;
//long? int64Group = null;
Expand Down Expand Up @@ -246,6 +246,22 @@ public void TestJsonFormDataTest()

}

/// <summary>
/// Test TestQueryParameterCollectionFormat
/// </summary>
[Test]
public void TestQueryParameterCollectionFormatTest()
{
// TODO uncomment below to test the method and replace null with proper value
//List<string> pipe = null;
//List<string> ioutil = null;
//List<string> http = null;
//List<string> url = null;
//List<string> context = null;
//instance.TestQueryParameterCollectionFormat(pipe, ioutil, http, url, context);

}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
* The version of the OpenAPI document: 1.0.0
*
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
Expand Down Expand Up @@ -58,8 +58,8 @@ public void Cleanup()
[Test]
public void InstanceTest()
{
// TODO uncomment below to test 'IsInstanceOfType' FakeClassnameTags123Api
//Assert.IsInstanceOfType(typeof(FakeClassnameTags123Api), instance, "instance is a FakeClassnameTags123Api");
// TODO uncomment below to test 'IsInstanceOf' FakeClassnameTags123Api
//Assert.IsInstanceOf(typeof(FakeClassnameTags123Api), instance);
}


Expand All @@ -72,7 +72,7 @@ public void TestClassnameTest()
// TODO uncomment below to test the method and replace null with proper value
//ModelClient body = null;
//var response = instance.TestClassname(body);
//Assert.IsInstanceOf<ModelClient> (response, "response is ModelClient");
//Assert.IsInstanceOf(typeof(ModelClient), response, "response is ModelClient");
}

}
Expand Down
Loading

0 comments on commit 5693cb9

Please sign in to comment.