diff --git a/abstractions/dotnet/Microsoft.Kiota.Abstractions.Tests/Serialization/ParseNodeFactoryRegistryTests.cs b/abstractions/dotnet/Microsoft.Kiota.Abstractions.Tests/Serialization/ParseNodeFactoryRegistryTests.cs
index ab18059574..e14c0c4dcf 100644
--- a/abstractions/dotnet/Microsoft.Kiota.Abstractions.Tests/Serialization/ParseNodeFactoryRegistryTests.cs
+++ b/abstractions/dotnet/Microsoft.Kiota.Abstractions.Tests/Serialization/ParseNodeFactoryRegistryTests.cs
@@ -6,7 +6,7 @@
using Moq;
using Xunit;
-namespace Microsoft.Kiota.Abstractions.Tests.serialization
+namespace Microsoft.Kiota.Abstractions.Tests.Serialization
{
public class ParseNodeFactoryRegistryTests
{
diff --git a/abstractions/dotnet/src/IRequestAdapter.cs b/abstractions/dotnet/src/IRequestAdapter.cs
index 830f554ebc..61da556f49 100644
--- a/abstractions/dotnet/src/IRequestAdapter.cs
+++ b/abstractions/dotnet/src/IRequestAdapter.cs
@@ -3,6 +3,7 @@
// ------------------------------------------------------------------------------
using System.Collections.Generic;
+using System.Threading;
using System.Threading.Tasks;
using Microsoft.Kiota.Abstractions.Serialization;
using Microsoft.Kiota.Abstractions.Store;
@@ -28,36 +29,41 @@ public interface IRequestAdapter
///
/// The RequestInformation object to use for the HTTP request.
/// The response handler to use for the HTTP request instead of the default handler.
+ /// The to use for cancelling the requests.
/// The deserialized response model.
- Task SendAsync(RequestInformation requestInfo, IResponseHandler responseHandler = default) where ModelType : IParsable;
+ Task SendAsync(RequestInformation requestInfo, IResponseHandler responseHandler = default, CancellationToken cancellationToken = default) where ModelType : IParsable;
///
/// Executes the HTTP request specified by the given RequestInformation and returns the deserialized response model collection.
///
/// The RequestInformation object to use for the HTTP request.
/// The response handler to use for the HTTP request instead of the default handler.
+ /// The to use for cancelling the requests.
/// The deserialized response model collection.
- Task> SendCollectionAsync(RequestInformation requestInfo, IResponseHandler responseHandler = default) where ModelType : IParsable;
+ Task> SendCollectionAsync(RequestInformation requestInfo, IResponseHandler responseHandler = default, CancellationToken cancellationToken = default) where ModelType : IParsable;
///
/// Executes the HTTP request specified by the given RequestInformation and returns the deserialized primitive response model.
///
/// The RequestInformation object to use for the HTTP request.
/// The response handler to use for the HTTP request instead of the default handler.
+ /// The to use for cancelling the requests.
/// The deserialized primitive response model.
- Task SendPrimitiveAsync(RequestInformation requestInfo, IResponseHandler responseHandler = default);
+ Task SendPrimitiveAsync(RequestInformation requestInfo, IResponseHandler responseHandler = default, CancellationToken cancellationToken = default);
///
/// Executes the HTTP request specified by the given RequestInformation and returns the deserialized primitive response model collection.
///
/// The RequestInformation object to use for the HTTP request.
/// The response handler to use for the HTTP request instead of the default handler.
+ /// The to use for cancelling the requests.
/// The deserialized primitive response model collection.
- Task> SendPrimitiveCollectionAsync(RequestInformation requestInfo, IResponseHandler responseHandler = default);
+ Task> SendPrimitiveCollectionAsync(RequestInformation requestInfo, IResponseHandler responseHandler = default, CancellationToken cancellationToken = default);
///
/// Executes the HTTP request specified by the given RequestInformation with no return content.
///
/// The RequestInformation object to use for the HTTP request.
/// The response handler to use for the HTTP request instead of the default handler.
+ /// The to use for cancelling the requests.
/// A Task to await completion.
- Task SendNoContentAsync(RequestInformation requestInfo, IResponseHandler responseHandler = default);
+ Task SendNoContentAsync(RequestInformation requestInfo, IResponseHandler responseHandler = default, CancellationToken cancellationToken = default);
///
/// The base url for every request.
///
diff --git a/abstractions/dotnet/src/Microsoft.Kiota.Abstractions.csproj b/abstractions/dotnet/src/Microsoft.Kiota.Abstractions.csproj
index 153bee9c6e..96341a8a70 100644
--- a/abstractions/dotnet/src/Microsoft.Kiota.Abstractions.csproj
+++ b/abstractions/dotnet/src/Microsoft.Kiota.Abstractions.csproj
@@ -6,7 +6,7 @@
latest
true
https://github.com/microsoft/kiota
- 1.0.24
+ 1.0.25
true
true
diff --git a/http/dotnet/httpclient/src/HttpClientRequestAdapter.cs b/http/dotnet/httpclient/src/HttpClientRequestAdapter.cs
index a832f46fa5..208c486900 100644
--- a/http/dotnet/httpclient/src/HttpClientRequestAdapter.cs
+++ b/http/dotnet/httpclient/src/HttpClientRequestAdapter.cs
@@ -12,6 +12,7 @@
using Microsoft.Kiota.Abstractions.Serialization;
using Microsoft.Kiota.Abstractions.Store;
using Microsoft.Kiota.Abstractions.Authentication;
+using System.Threading;
namespace Microsoft.Kiota.Http.HttpClientLibrary
{
@@ -57,9 +58,10 @@ public ISerializationWriterFactory SerializationWriterFactory
///
/// The instance to send
/// The to use with the response
- public async Task> SendCollectionAsync(RequestInformation requestInfo, IResponseHandler responseHandler = default) where ModelType : IParsable
+ /// The to use for cancelling the request.
+ public async Task> SendCollectionAsync(RequestInformation requestInfo, IResponseHandler responseHandler = default, CancellationToken cancellationToken = default) where ModelType : IParsable
{
- var response = await GetHttpResponseMessage(requestInfo);
+ var response = await GetHttpResponseMessage(requestInfo, cancellationToken);
requestInfo.Content?.Dispose();
if(responseHandler == null)
{
@@ -75,9 +77,10 @@ public async Task> SendCollectionAsync(Request
///
/// The RequestInformation object to use for the HTTP request.
/// The response handler to use for the HTTP request instead of the default handler.
+ /// The to use for cancelling the request.
/// The deserialized primitive response model collection.
- public async Task> SendPrimitiveCollectionAsync(RequestInformation requestInfo, IResponseHandler responseHandler = default) {
- var response = await GetHttpResponseMessage(requestInfo);
+ public async Task> SendPrimitiveCollectionAsync(RequestInformation requestInfo, IResponseHandler responseHandler = default, CancellationToken cancellationToken = default) {
+ var response = await GetHttpResponseMessage(requestInfo, cancellationToken);
requestInfo.Content?.Dispose();
if(responseHandler == null)
{
@@ -93,9 +96,11 @@ public async Task> SendPrimitiveCollectionAsync
/// The instance to send
/// The to use with the response
- public async Task SendAsync(RequestInformation requestInfo, IResponseHandler responseHandler = null) where ModelType : IParsable
+ /// The to use for cancelling the request.
+ /// The deserialized response model.
+ public async Task SendAsync(RequestInformation requestInfo, IResponseHandler responseHandler = null, CancellationToken cancellationToken = default) where ModelType : IParsable
{
- var response = await GetHttpResponseMessage(requestInfo);
+ var response = await GetHttpResponseMessage(requestInfo, cancellationToken);
requestInfo.Content?.Dispose();
if(responseHandler == null)
{
@@ -111,10 +116,11 @@ public async Task SendAsync(RequestInformation requestInfo
///
/// The instance to send
/// The to use with the response
- ///
- public async Task SendPrimitiveAsync(RequestInformation requestInfo, IResponseHandler responseHandler = default)
+ /// The to use for cancelling the request.
+ /// The deserialized primitive response model.
+ public async Task SendPrimitiveAsync(RequestInformation requestInfo, IResponseHandler responseHandler = default, CancellationToken cancellationToken = default)
{
- var response = await GetHttpResponseMessage(requestInfo);
+ var response = await GetHttpResponseMessage(requestInfo, cancellationToken);
requestInfo.Content?.Dispose();
if(responseHandler == null)
{
@@ -167,10 +173,11 @@ public async Task SendPrimitiveAsync(RequestInformation re
///
/// The instance to send
/// The to use with the response
+ /// The to use for cancelling the request.
///
- public async Task SendNoContentAsync(RequestInformation requestInfo, IResponseHandler responseHandler = null)
+ public async Task SendNoContentAsync(RequestInformation requestInfo, IResponseHandler responseHandler = null, CancellationToken cancellationToken = default)
{
- var response = await GetHttpResponseMessage(requestInfo);
+ var response = await GetHttpResponseMessage(requestInfo, cancellationToken);
requestInfo.Content?.Dispose();
if(responseHandler == null)
response.Dispose();
@@ -187,7 +194,7 @@ private async Task GetRootParseNode(HttpResponseMessage response)
response.Dispose();
return rootNode;
}
- private async Task GetHttpResponseMessage(RequestInformation requestInfo)
+ private async Task GetHttpResponseMessage(RequestInformation requestInfo, CancellationToken cancellationToken)
{
if(requestInfo == null)
throw new ArgumentNullException(nameof(requestInfo));
@@ -195,7 +202,7 @@ private async Task GetHttpResponseMessage(RequestInformatio
await authProvider.AuthenticateRequestAsync(requestInfo);
using var message = GetRequestMessageFromRequestInformation(requestInfo);
- var response = await this.client.SendAsync(message);
+ var response = await this.client.SendAsync(message,cancellationToken);
if(response == null)
throw new InvalidOperationException("Could not get a response after calling the service");
return response;
diff --git a/http/dotnet/httpclient/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj b/http/dotnet/httpclient/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj
index 98af884434..62a5973110 100644
--- a/http/dotnet/httpclient/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj
+++ b/http/dotnet/httpclient/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj
@@ -6,7 +6,7 @@
latest
true
https://github.com/microsoft/kiota
- 1.0.15
+ 1.0.16
true
@@ -14,7 +14,7 @@
-
+
diff --git a/src/Kiota.Builder/CodeDOM/CodeParameter.cs b/src/Kiota.Builder/CodeDOM/CodeParameter.cs
index a6fe7cdca9..52c231e87f 100644
--- a/src/Kiota.Builder/CodeDOM/CodeParameter.cs
+++ b/src/Kiota.Builder/CodeDOM/CodeParameter.cs
@@ -29,6 +29,10 @@ public enum CodeParameterKind
/// Only used for languages that do not support overloads or optional parameters like go.
///
ParameterSet,
+ ///
+ /// A single parameter to be provided by the SDK user which can be used to cancel requests.
+ ///
+ Cancellation
}
public class CodeParameter : CodeTerminal, ICloneable, IDocumentedElement
diff --git a/src/Kiota.Builder/KiotaBuilder.cs b/src/Kiota.Builder/KiotaBuilder.cs
index b275350085..fa5b705c2d 100644
--- a/src/Kiota.Builder/KiotaBuilder.cs
+++ b/src/Kiota.Builder/KiotaBuilder.cs
@@ -579,7 +579,16 @@ private void CreateOperationMethods(OpenApiUrlTreeNode currentNode, OperationTyp
Description = "Response handler to use in place of the default response handling provided by the core service",
Type = new CodeType { Name = "IResponseHandler", IsExternal = true },
};
- executorMethod.AddParameter(handlerParam);
+ executorMethod.AddParameter(handlerParam);// Add response handler parameter
+
+ var cancellationParam = new CodeParameter{
+ Name = "cancellationToken",
+ Optional = true,
+ ParameterKind = CodeParameterKind.Cancellation,
+ Description = "Cancellation token to use when cancelling requests",
+ Type = new CodeType { Name = "CancellationToken", IsExternal = true },
+ };
+ executorMethod.AddParameter(cancellationParam);// Add cancellation token parameter
logger.LogTrace("Creating method {name} of {type}", executorMethod.Name, executorMethod.ReturnType);
var generatorMethod = new CodeMethod {
diff --git a/src/Kiota.Builder/Refiners/CSharpRefiner.cs b/src/Kiota.Builder/Refiners/CSharpRefiner.cs
index db517d51c4..17473868a4 100644
--- a/src/Kiota.Builder/Refiners/CSharpRefiner.cs
+++ b/src/Kiota.Builder/Refiners/CSharpRefiner.cs
@@ -93,6 +93,8 @@ parentClass.StartBlock is CodeClass.Declaration parentDeclaration ?
"System.Collections.Generic", "List", "Dictionary"),
new (x => x is CodeClass @class && @class.IsOfKind(CodeClassKind.Model, CodeClassKind.RequestBuilder),
"System.IO", "Stream"),
+ new (x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.RequestExecutor),
+ "System.Threading", "CancellationToken"),
new (x => x is CodeClass @class && @class.IsOfKind(CodeClassKind.RequestBuilder),
"System.Threading.Tasks", "Task"),
new (x => x is CodeClass @class && @class.IsOfKind(CodeClassKind.Model, CodeClassKind.RequestBuilder),
diff --git a/src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs b/src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs
index 251fa551af..d4da51fae1 100644
--- a/src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs
+++ b/src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Linq;
using Kiota.Builder.Extensions;
@@ -489,5 +489,12 @@ currentElement.Parent is CodeClass parentClass &&
}
CrawlTree(currentElement, AddRawUrlConstructorOverload);
}
+ protected static void RemoveCancellationParameter(CodeElement currentElement){
+ if (currentElement is CodeMethod currentMethod &&
+ currentMethod.IsOfKind(CodeMethodKind.RequestExecutor)){
+ currentMethod.RemoveParametersByKind(CodeParameterKind.Cancellation);
+ }
+ CrawlTree(currentElement, RemoveCancellationParameter);
+ }
}
}
diff --git a/src/Kiota.Builder/Refiners/GoRefiner.cs b/src/Kiota.Builder/Refiners/GoRefiner.cs
index f9a1a5fe69..e5e3a4a9cd 100644
--- a/src/Kiota.Builder/Refiners/GoRefiner.cs
+++ b/src/Kiota.Builder/Refiners/GoRefiner.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Linq;
using Kiota.Builder.Extensions;
using Kiota.Builder.Writers.Extensions;
@@ -19,6 +19,7 @@ public override void Refine(CodeNamespace generatedCode)
generatedCode,
false,
"ById");
+ RemoveCancellationParameter(generatedCode);
ReplaceRequestBuilderPropertiesByMethods(
generatedCode
);
diff --git a/src/Kiota.Builder/Refiners/JavaRefiner.cs b/src/Kiota.Builder/Refiners/JavaRefiner.cs
index c6b5691284..8141b5408d 100644
--- a/src/Kiota.Builder/Refiners/JavaRefiner.cs
+++ b/src/Kiota.Builder/Refiners/JavaRefiner.cs
@@ -11,6 +11,7 @@ public override void Refine(CodeNamespace generatedCode)
AddInnerClasses(generatedCode, false);
InsertOverrideMethodForRequestExecutorsAndBuildersAndConstructors(generatedCode);
ReplaceIndexersByMethodsWithParameter(generatedCode, generatedCode, true);
+ RemoveCancellationParameter(generatedCode);
ConvertUnionTypesToWrapper(generatedCode, _configuration.UsesBackingStore);
AddRawUrlConstructorOverload(generatedCode);
ReplaceReservedNames(generatedCode, new JavaReservedNamesProvider(), x => $"{x}_escaped");
diff --git a/src/Kiota.Builder/Refiners/RubyRefiner.cs b/src/Kiota.Builder/Refiners/RubyRefiner.cs
index 508c69af6a..f5e8ee292a 100644
--- a/src/Kiota.Builder/Refiners/RubyRefiner.cs
+++ b/src/Kiota.Builder/Refiners/RubyRefiner.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Linq;
using Kiota.Builder.Extensions;
@@ -11,6 +11,7 @@ public override void Refine(CodeNamespace generatedCode)
{
ReplaceIndexersByMethodsWithParameter(generatedCode, generatedCode, false, "_by_id");
AddPropertiesAndMethodTypesImports(generatedCode, false, false, false);
+ RemoveCancellationParameter(generatedCode);
AddParsableInheritanceForModelClasses(generatedCode);
AddInheritedAndMethodTypesImports(generatedCode);
AddDefaultImports(generatedCode, defaultUsingEvaluators);
diff --git a/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs b/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs
index f86e6b4f7c..b16639ce07 100644
--- a/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs
+++ b/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs
@@ -1,4 +1,4 @@
-using System.Linq;
+using System.Linq;
using System;
using Kiota.Builder.Extensions;
@@ -10,6 +10,7 @@ public override void Refine(CodeNamespace generatedCode)
{
AddDefaultImports(generatedCode, defaultUsingEvaluators);
ReplaceIndexersByMethodsWithParameter(generatedCode, generatedCode, false, "ById");
+ RemoveCancellationParameter(generatedCode);
CorrectCoreType(generatedCode, CorrectMethodType, CorrectPropertyType);
CorrectCoreTypesForBackingStore(generatedCode, "BackingStoreFactorySingleton.instance.createBackingStore()");
AddPropertiesAndMethodTypesImports(generatedCode, true, true, true);
diff --git a/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs
index 85abef5d2d..3cb91f2edf 100644
--- a/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs
+++ b/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs
@@ -178,7 +178,7 @@ private void WriteRequestExecutorBody(CodeMethod codeElement, RequestParams requ
var parametersList = new CodeParameter[] { requestParams.requestBody, requestParams.queryString, requestParams.headers, requestParams.options }
.Select(x => x?.Name).Where(x => x != null).Aggregate((x,y) => $"{x}, {y}");
writer.WriteLine($"var requestInfo = {generatorMethodName}({parametersList});");
- writer.WriteLine($"{(isVoid ? string.Empty : "return ")}await RequestAdapter.{GetSendRequestMethodName(isVoid, isStream, codeElement.ReturnType.IsCollection, returnType)}(requestInfo, responseHandler);");
+ writer.WriteLine($"{(isVoid ? string.Empty : "return ")}await RequestAdapter.{GetSendRequestMethodName(isVoid, isStream, codeElement.ReturnType.IsCollection, returnType)}(requestInfo, responseHandler, cancellationToken);");
}
private const string RequestInfoVarName = "requestInfo";
private void WriteRequestGeneratorBody(CodeMethod codeElement, RequestParams requestParams, CodeClass currentClass, LanguageWriter writer) {
diff --git a/tests/Kiota.Builder.Tests/Refiners/CSharpLanguageRefinerTests.cs b/tests/Kiota.Builder.Tests/Refiners/CSharpLanguageRefinerTests.cs
index e8c3bb939c..19a6c8bc7e 100644
--- a/tests/Kiota.Builder.Tests/Refiners/CSharpLanguageRefinerTests.cs
+++ b/tests/Kiota.Builder.Tests/Refiners/CSharpLanguageRefinerTests.cs
@@ -81,6 +81,35 @@ public void MovesClassesWithNamespaceNamesUnderNamespace() {
Assert.Single(modelNS.GetChildElements(true));
Assert.Equal(modelNS, model.Parent);
}
+ [Fact]
+ public void KeepsCancellationParametersInRequestExecutors()
+ {
+ var model = root.AddClass(new CodeClass
+ {
+ Name = "model",
+ ClassKind = CodeClassKind.RequestBuilder
+ }).First();
+ var method = model.AddMethod(new CodeMethod
+ {
+ Name = "getMethod",
+ MethodKind = CodeMethodKind.RequestExecutor,
+ ReturnType = new CodeType {
+ Name = "string"
+ }
+ }).First();
+ var cancellationParam = new CodeParameter
+ {
+ Name = "cancelletionToken",
+ Optional = true,
+ ParameterKind = CodeParameterKind.Cancellation,
+ Description = "Cancellation token to use when cancelling requests",
+ Type = new CodeType { Name = "CancelletionToken", IsExternal = true },
+ };
+ method.AddParameter(cancellationParam);
+ ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.CSharp }, root); //using CSharp so the cancelletionToken doesn't get removed
+ Assert.True(method.Parameters.Any());
+ Assert.Contains(cancellationParam, method.Parameters);
+ }
#endregion
#region CSharp
[Fact]
diff --git a/tests/Kiota.Builder.Tests/Refiners/GoLanguageRefinerTests.cs b/tests/Kiota.Builder.Tests/Refiners/GoLanguageRefinerTests.cs
index 2222de60f1..a6bac5b6e0 100644
--- a/tests/Kiota.Builder.Tests/Refiners/GoLanguageRefinerTests.cs
+++ b/tests/Kiota.Builder.Tests/Refiners/GoLanguageRefinerTests.cs
@@ -1,11 +1,40 @@
-using System.Linq;
+using System.Linq;
using Xunit;
namespace Kiota.Builder.Refiners.Tests {
public class GoLanguageRefinerTests {
private readonly CodeNamespace root = CodeNamespace.InitRootNamespace();
#region CommonLangRefinerTests
-
+ [Fact]
+ public void DoesNotKeepCancellationParametersInRequestExecutors()
+ {
+ var model = root.AddClass(new CodeClass
+ {
+ Name = "model",
+ ClassKind = CodeClassKind.RequestBuilder
+ }).First();
+ var method = model.AddMethod(new CodeMethod
+ {
+ Name = "getMethod",
+ MethodKind = CodeMethodKind.RequestExecutor,
+ ReturnType = new CodeType
+ {
+ Name = "string"
+ }
+ }).First();
+ var cancellationParam = new CodeParameter
+ {
+ Name = "cancelletionToken",
+ Optional = true,
+ ParameterKind = CodeParameterKind.Cancellation,
+ Description = "Cancellation token to use when cancelling requests",
+ Type = new CodeType { Name = "CancelletionToken", IsExternal = true },
+ };
+ method.AddParameter(cancellationParam);
+ ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.Go }, root); //using CSharp so the cancelletionToken doesn't get removed
+ Assert.False(method.Parameters.Any());
+ Assert.DoesNotContain(cancellationParam, method.Parameters);
+ }
#endregion
#region GoRefinerTests
diff --git a/tests/Kiota.Builder.Tests/Refiners/JavaLanguageRefinerTests.cs b/tests/Kiota.Builder.Tests/Refiners/JavaLanguageRefinerTests.cs
index 292a02024c..1c8a37634e 100644
--- a/tests/Kiota.Builder.Tests/Refiners/JavaLanguageRefinerTests.cs
+++ b/tests/Kiota.Builder.Tests/Refiners/JavaLanguageRefinerTests.cs
@@ -1,4 +1,4 @@
-using System.Linq;
+using System.Linq;
using Xunit;
namespace Kiota.Builder.Refiners.Tests {
@@ -136,6 +136,36 @@ public void AddsInnerClasses() {
ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.Java }, root);
Assert.Equal(2, model.GetChildElements(true).Count());
}
+ [Fact]
+ public void DoesNotKeepCancellationParametersInRequestExecutors()
+ {
+ var model = root.AddClass(new CodeClass
+ {
+ Name = "model",
+ ClassKind = CodeClassKind.RequestBuilder
+ }).First();
+ var method = model.AddMethod(new CodeMethod
+ {
+ Name = "getMethod",
+ MethodKind = CodeMethodKind.RequestExecutor,
+ ReturnType = new CodeType
+ {
+ Name = "string"
+ }
+ }).First();
+ var cancellationParam = new CodeParameter
+ {
+ Name = "cancelletionToken",
+ Optional = true,
+ ParameterKind = CodeParameterKind.Cancellation,
+ Description = "Cancellation token to use when cancelling requests",
+ Type = new CodeType { Name = "CancelletionToken", IsExternal = true },
+ };
+ method.AddParameter(cancellationParam);
+ ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.Java }, root); //using CSharp so the cancelletionToken doesn't get removed
+ Assert.False(method.Parameters.Any());
+ Assert.DoesNotContain(cancellationParam, method.Parameters);
+ }
#endregion
#region JavaLanguageRefinerTests
[Fact]
diff --git a/tests/Kiota.Builder.Tests/Refiners/RubyLanguageRefinerTests.cs b/tests/Kiota.Builder.Tests/Refiners/RubyLanguageRefinerTests.cs
index da0d022c59..61a69f4408 100644
--- a/tests/Kiota.Builder.Tests/Refiners/RubyLanguageRefinerTests.cs
+++ b/tests/Kiota.Builder.Tests/Refiners/RubyLanguageRefinerTests.cs
@@ -1,4 +1,4 @@
-using System.Linq;
+using System.Linq;
using Xunit;
namespace Kiota.Builder.Refiners.Tests {
@@ -17,6 +17,36 @@ public RubyLanguageRefinerTests() {
}
#region CommonLanguageRefinerTests
[Fact]
+ public void DoesNotKeepCancellationParametersInRequestExecutors()
+ {
+ var model = root.AddClass(new CodeClass
+ {
+ Name = "model",
+ ClassKind = CodeClassKind.RequestBuilder
+ }).First();
+ var method = model.AddMethod(new CodeMethod
+ {
+ Name = "getMethod",
+ MethodKind = CodeMethodKind.RequestExecutor,
+ ReturnType = new CodeType
+ {
+ Name = "string"
+ }
+ }).First();
+ var cancellationParam = new CodeParameter
+ {
+ Name = "cancelletionToken",
+ Optional = true,
+ ParameterKind = CodeParameterKind.Cancellation,
+ Description = "Cancellation token to use when cancelling requests",
+ Type = new CodeType { Name = "CancelletionToken", IsExternal = true },
+ };
+ method.AddParameter(cancellationParam);
+ ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.Ruby }, root); //using CSharp so the cancelletionToken doesn't get removed
+ Assert.False(method.Parameters.Any());
+ Assert.DoesNotContain(cancellationParam, method.Parameters);
+ }
+ [Fact]
public void AddsDefaultImports() {
var model = root.AddClass(new CodeClass {
Name = "model",
diff --git a/tests/Kiota.Builder.Tests/Refiners/TypeScriptLanguageRefinerTests.cs b/tests/Kiota.Builder.Tests/Refiners/TypeScriptLanguageRefinerTests.cs
index f833e8eae2..4daaa7ff2c 100644
--- a/tests/Kiota.Builder.Tests/Refiners/TypeScriptLanguageRefinerTests.cs
+++ b/tests/Kiota.Builder.Tests/Refiners/TypeScriptLanguageRefinerTests.cs
@@ -161,6 +161,36 @@ public void AliasesDuplicateUsingSymbols() {
Assert.NotEmpty(using2.Alias);
Assert.NotEqual(using1.Alias, using2.Alias);
}
+ [Fact]
+ public void DoesNotKeepCancellationParametersInRequestExecutors()
+ {
+ var model = root.AddClass(new CodeClass
+ {
+ Name = "model",
+ ClassKind = CodeClassKind.RequestBuilder
+ }).First();
+ var method = model.AddMethod(new CodeMethod
+ {
+ Name = "getMethod",
+ MethodKind = CodeMethodKind.RequestExecutor,
+ ReturnType = new CodeType
+ {
+ Name = "string"
+ }
+ }).First();
+ var cancellationParam = new CodeParameter
+ {
+ Name = "cancelletionToken",
+ Optional = true,
+ ParameterKind = CodeParameterKind.Cancellation,
+ Description = "Cancellation token to use when cancelling requests",
+ Type = new CodeType { Name = "CancelletionToken", IsExternal = true },
+ };
+ method.AddParameter(cancellationParam);
+ ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.TypeScript }, root); //using CSharp so the cancelletionToken doesn't get removed
+ Assert.False(method.Parameters.Any());
+ Assert.DoesNotContain(cancellationParam, method.Parameters);
+ }
#endregion
}
}
diff --git a/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs
index 0689f02a35..4cbfa1efee 100644
--- a/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs
+++ b/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs
@@ -130,6 +130,12 @@ private void AddRequestBodyParameters() {
ParameterKind = CodeParameterKind.Options,
Type = stringType,
});
+ method.AddParameter(new CodeParameter
+ {
+ Name = "c",
+ ParameterKind = CodeParameterKind.Cancellation,
+ Type = stringType,
+ });
}
[Fact]
public void WritesRequestBuilder() {
@@ -154,6 +160,7 @@ public void WritesRequestExecutorBody() {
Assert.Contains("SendAsync", result);
Assert.Contains(AsyncKeyword, result);
Assert.Contains("await", result);
+ Assert.Contains("cancellationToken", result);
AssertExtensions.CurlyBracesAreClosed(result);
}
[Fact]
@@ -165,6 +172,7 @@ public void WritesRequestExecutorBodyForCollections() {
writer.Write(method);
var result = tw.ToString();
Assert.Contains("SendCollectionAsync", result);
+ Assert.Contains("cancellationToken", result);
AssertExtensions.CurlyBracesAreClosed(result);
}
[Fact]