diff --git a/src/AutoRest.CSharp/Common/Generation/Writers/PageableMethodsWriterExtensions.cs b/src/AutoRest.CSharp/Common/Generation/Writers/PageableMethodsWriterExtensions.cs index 44acb172e12..bbf1bd5597c 100644 --- a/src/AutoRest.CSharp/Common/Generation/Writers/PageableMethodsWriterExtensions.cs +++ b/src/AutoRest.CSharp/Common/Generation/Writers/PageableMethodsWriterExtensions.cs @@ -219,7 +219,7 @@ private static bool ContainsRequestContext(IReadOnlyCollection? param continue; } - var convenienceParameter = ProtocolToConvenienceParameterConverters.FirstOrDefault(convert => convert.Convenience.Name == parameter.Name)?.Convenience; + var convenienceParameter = ProtocolToConvenienceParameterConverters.FirstOrDefault(convert => convert.Convenience?.Name == parameter.Name)?.Convenience; if (convenienceParameter == null) { throw new InvalidOperationException($"Cannot find corresponding convenience parameter for create request method parameter {parameter.Name}."); diff --git a/src/AutoRest.CSharp/Common/Output/Expressions/Snippets.cs b/src/AutoRest.CSharp/Common/Output/Expressions/Snippets.cs index 3f89b2b6589..19b6cdef4d9 100644 --- a/src/AutoRest.CSharp/Common/Output/Expressions/Snippets.cs +++ b/src/AutoRest.CSharp/Common/Output/Expressions/Snippets.cs @@ -25,6 +25,8 @@ internal static partial class Snippets public static ValueExpression Dash { get; } = new KeywordExpression("_", null); public static ValueExpression Default { get; } = new KeywordExpression("default", null); public static ValueExpression Null { get; } = new KeywordExpression("null", null); + + public static ValueExpression DefaultOf(CSharpType type) => type is { IsValueType: true, IsNullable: false } ? Default.CastTo(type) : Null.CastTo(type); public static ValueExpression This { get; } = new KeywordExpression("this", null); public static BoolExpression True { get; } = new(new KeywordExpression("true", null)); public static BoolExpression False { get; } = new(new KeywordExpression("false", null)); @@ -35,7 +37,7 @@ internal static partial class Snippets public static ValueExpression Float(float value) => new FormattableStringToExpression($"{value}f"); public static ValueExpression Double(double value) => new FormattableStringToExpression($"{value}d"); - public static ValueExpression Nameof(ValueExpression expression) => new InvokeInstanceMethodExpression(null, "nameof", new[]{expression}, null, false); + public static ValueExpression Nameof(ValueExpression expression) => new InvokeInstanceMethodExpression(null, "nameof", new[] { expression }, null, false); public static ValueExpression ThrowExpression(ValueExpression expression) => new KeywordExpression("throw", expression); public static ValueExpression NullCoalescing(ValueExpression left, ValueExpression right) => new BinaryOperatorExpression("??", left, right); @@ -46,8 +48,8 @@ public static ValueExpression RemoveAllNullConditional(ValueExpression expressio => expression switch { NullConditionalExpression nullConditional => RemoveAllNullConditional(nullConditional.Inner), - MemberExpression { Inner: {} inner } member => member with {Inner = RemoveAllNullConditional(inner)}, - TypedValueExpression typed => typed with { Untyped = RemoveAllNullConditional(typed.Untyped)}, + MemberExpression { Inner: { } inner } member => member with { Inner = RemoveAllNullConditional(inner) }, + TypedValueExpression typed => typed with { Untyped = RemoveAllNullConditional(typed.Untyped) }, _ => expression }; @@ -86,9 +88,9 @@ public static EnumerableExpression InvokeArrayEmpty(CSharpType arrayItemType) => new(arrayItemType, new InvokeStaticMethodExpression(typeof(Array), nameof(Array.Empty), Array.Empty(), new[] { arrayItemType })); public static StreamExpression InvokeFileOpenRead(string filePath) - => new(new InvokeStaticMethodExpression(typeof(System.IO.File), nameof(System.IO.File.OpenRead), new[]{Literal(filePath)})); + => new(new InvokeStaticMethodExpression(typeof(System.IO.File), nameof(System.IO.File.OpenRead), new[] { Literal(filePath) })); public static StreamExpression InvokeFileOpenWrite(string filePath) - => new(new InvokeStaticMethodExpression(typeof(System.IO.File), nameof(System.IO.File.OpenWrite), new[]{Literal(filePath)})); + => new(new InvokeStaticMethodExpression(typeof(System.IO.File), nameof(System.IO.File.OpenWrite), new[] { Literal(filePath) })); // Expected signature: MethodName(Utf8JsonWriter writer); public static MethodBodyStatement InvokeCustomSerializationMethod(string methodName, Utf8JsonWriterExpression utf8JsonWriter) @@ -100,7 +102,7 @@ public static MethodBodyStatement InvokeCustomBicepSerializationMethod(string me // Expected signature: MethodName(JsonProperty property, ref T optional) public static MethodBodyStatement InvokeCustomDeserializationMethod(string methodName, JsonPropertyExpression jsonProperty, CodeWriterDeclaration variable) - => new InvokeStaticMethodStatement(null, methodName, new ValueExpression[]{jsonProperty, new FormattableStringToExpression($"ref {variable}")}); + => new InvokeStaticMethodStatement(null, methodName, new ValueExpression[] { jsonProperty, new FormattableStringToExpression($"ref {variable}") }); public static AssignValueIfNullStatement AssignIfNull(ValueExpression variable, ValueExpression expression) => new(variable, expression); public static AssignValueStatement Assign(ValueExpression variable, ValueExpression expression) => new(variable, expression); diff --git a/src/AutoRest.CSharp/LowLevel/Generation/DpgClientWriter.cs b/src/AutoRest.CSharp/LowLevel/Generation/DpgClientWriter.cs index e465466c6a9..495ec6dfdcb 100644 --- a/src/AutoRest.CSharp/LowLevel/Generation/DpgClientWriter.cs +++ b/src/AutoRest.CSharp/LowLevel/Generation/DpgClientWriter.cs @@ -94,7 +94,8 @@ public void WriteClient() WriteRequestCreationMethod(_writer, method, _client.Fields); } - if (_client.ClientMethods.Any(cm => cm.ConvenienceMethod is not null)) + // since the non-azure libraries do not have cancellationToken parameters on their convenience methods, we do not need to add the method to convert the cancellationToken to RequestContext + if (Configuration.IsBranded && _client.ClientMethods.Any(cm => cm.ConvenienceMethod is not null)) { WriteCancellationTokenToRequestContextMethod(); } diff --git a/src/AutoRest.CSharp/LowLevel/Output/ConvenienceMethod.cs b/src/AutoRest.CSharp/LowLevel/Output/ConvenienceMethod.cs index b9d3f397bce..f5cf85ed4cd 100644 --- a/src/AutoRest.CSharp/LowLevel/Output/ConvenienceMethod.cs +++ b/src/AutoRest.CSharp/LowLevel/Output/ConvenienceMethod.cs @@ -24,7 +24,7 @@ namespace AutoRest.CSharp.Output.Models { internal record ConvenienceMethod(MethodSignature Signature, IReadOnlyList ProtocolToConvenienceParameterConverters, CSharpType? ResponseType, IReadOnlyList? RequestMediaTypes, IReadOnlyList? ResponseMediaTypes, Diagnostic? Diagnostic, bool IsPageable, bool IsLongRunning, string? Deprecated) { - private record ConvenienceParameterInfo(Parameter Convenience, ConvenienceParameterSpread? ConvenienceSpread); + private record ConvenienceParameterInfo(Parameter? Convenience, ConvenienceParameterSpread? ConvenienceSpread); public IEnumerable GetConvertStatements(LowLevelClientMethod clientMethod, bool async, FieldDeclaration clientDiagnostics) { @@ -33,7 +33,7 @@ public IEnumerable GetConvertStatements(LowLevelClientMetho var protocolInvocationExpressions = new List(); foreach (var protocol in protocolMethod.Parameters) { - var (convenience, convenienceSpread) = parametersDict[protocol.Name]; // TODO -- maybe change it to name as keys? + var (convenience, convenienceSpread) = parametersDict[protocol.Name]; if (protocol == KnownParameters.RequestContext || protocol == KnownParameters.RequestContextRequired) { // convert cancellationToken to request context @@ -46,18 +46,15 @@ public IEnumerable GetConvertStatements(LowLevelClientMetho yield return Declare(context, new InvokeStaticMethodExpression(null, "FromCancellationToken", new ValueExpression[] { convenience })); protocolInvocationExpressions.Add(context); } - else if (!protocol.IsOptionalInSignature) - { - // when we do not have a cancellationToken, and the requestContext parameter is required in protocol signature, we pass a null - protocolInvocationExpressions.Add(Null.CastTo(protocol.Type)); - } else { - // do nothing + // if convenience parameter is null here, we just use the default value of the protocol parameter as value (we always do this even if the parameter is optional just in case there is an ordering issue) + protocolInvocationExpressions.Add(DefaultOf(protocol.Type)); } } else if (protocol == KnownParameters.RequestContent || protocol == KnownParameters.RequestContentNullable) { + Debug.Assert(convenience is not null); // convert body to request content if (convenienceSpread == null) { @@ -75,10 +72,17 @@ public IEnumerable GetConvertStatements(LowLevelClientMetho else { // process any other parameter - // in this case, convenience parameter should never be null - Debug.Assert(convenience is not null); - var expression = convenience.GetConversionToProtocol(protocol.Type, RequestMediaTypes?.FirstOrDefault()); - protocolInvocationExpressions.Add(expression); + if (convenience != null) + { + // if convenience parameter is not null here, we convert it to protocol parameter value properly + var expression = convenience.GetConversionToProtocol(protocol.Type, RequestMediaTypes?.FirstOrDefault()); + protocolInvocationExpressions.Add(expression); + } + else + { + // if convenience parameter is null here, we just use the default value of the protocol parameter as value (we always do this even if the parameter is optional just in case there is an ordering issue) + protocolInvocationExpressions.Add(DefaultOf(protocol.Type)); + } } } @@ -210,7 +214,7 @@ private MethodBodyStatement GetSpreadConversion(ConvenienceParameterSpread conve } } - internal record ProtocolToConvenienceParameterConverter(Parameter Protocol, Parameter Convenience, ConvenienceParameterSpread? ConvenienceSpread); + internal record ProtocolToConvenienceParameterConverter(Parameter Protocol, Parameter? Convenience, ConvenienceParameterSpread? ConvenienceSpread); internal record ConvenienceParameterSpread(ModelTypeProvider BackingModel, IReadOnlyList SpreadedParameters); } diff --git a/src/AutoRest.CSharp/LowLevel/Output/ConvenienceMethodOmittingMessage.cs b/src/AutoRest.CSharp/LowLevel/Output/ConvenienceMethodOmittingMessage.cs index b6cc9026b7d..e3ac298d8be 100644 --- a/src/AutoRest.CSharp/LowLevel/Output/ConvenienceMethodOmittingMessage.cs +++ b/src/AutoRest.CSharp/LowLevel/Output/ConvenienceMethodOmittingMessage.cs @@ -12,10 +12,6 @@ private ConvenienceMethodOmittingMessage(string message) public string Message { get; } - public static ConvenienceMethodOmittingMessage AnonymousModel = new("The convenience method of this operation is omitted because it is using at least one anonymous model"); - - public static ConvenienceMethodOmittingMessage NotConfident = new("The convenience method of this operation is made internal because this operation directly or indirectly uses a low confident type, for instance, unions, literal types with number values, etc."); - public static ConvenienceMethodOmittingMessage NotMeaningful = new("The convenience method is omitted here because it has exactly the same parameter list as the corresponding protocol method"); } } diff --git a/src/AutoRest.CSharp/LowLevel/Output/OperationMethodChainBuilder.cs b/src/AutoRest.CSharp/LowLevel/Output/OperationMethodChainBuilder.cs index 40dd44a409c..681cb8b659b 100644 --- a/src/AutoRest.CSharp/LowLevel/Output/OperationMethodChainBuilder.cs +++ b/src/AutoRest.CSharp/LowLevel/Output/OperationMethodChainBuilder.cs @@ -96,12 +96,15 @@ public LowLevelClientMethod BuildOperationMethodChain() ? new[] { new CSharpAttribute(typeof(ObsoleteAttribute), Literal(deprecated)) } : Array.Empty(); - var shouldRequestContextOptional = ShouldRequestContextOptional(); - var protocolMethodParameters = _orderedParameters.Select(p => p.Protocol).WhereNotNull().Select(p => p != KnownParameters.RequestContentNullable && !shouldRequestContextOptional ? p.ToRequired() : p).ToArray(); + var isRequestContextOptional = _orderedParameters.Any(p => p.Protocol == KnownParameters.RequestContext); + // because request context is always the last parameter, when request context is changed to required by some reason, all parameters before it (which means all parameters) should be required + var protocolMethodParameters = isRequestContextOptional + ? _orderedParameters.Select(p => p.Protocol).WhereNotNull().ToArray() + : _orderedParameters.Select(p => p.Protocol?.ToRequired()).WhereNotNull().ToArray(); var protocolMethodModifiers = (Operation.GenerateProtocolMethod ? _restClientMethod.Accessibility : Internal) | Virtual; var protocolMethodSignature = new MethodSignature(_restClientMethod.Name, FormattableStringHelpers.FromString(_restClientMethod.Summary), FormattableStringHelpers.FromString(_restClientMethod.Description), protocolMethodModifiers, _returnType.Protocol, null, protocolMethodParameters, protocolMethodAttributes); var convenienceMethodInfo = ShouldGenerateConvenienceMethod(); - var convenienceMethod = BuildConvenienceMethod(shouldRequestContextOptional, convenienceMethodInfo); + var convenienceMethod = BuildConvenienceMethod(isRequestContextOptional, convenienceMethodInfo); var diagnostic = new Diagnostic($"{_clientName}.{_restClientMethod.Name}"); @@ -202,7 +205,7 @@ private ConvenienceMethodGenerationInfo ShouldGenerateConvenienceMethod() // If all the corresponding parameters and return types of convenience method and protocol method have the same type, it does not make sense to generate the convenience method. private bool IsConvenienceMethodMeaningful() { - return _orderedParameters.Where(parameter => parameter.Convenience != KnownParameters.CancellationTokenParameter).Any(parameter => !IsParameterTypeSame(parameter.Convenience, parameter.Protocol)) + return _orderedParameters.Where(parameter => parameter.Protocol != KnownParameters.RequestContext && parameter.Protocol != KnownParameters.RequestContextRequired).Any(parameter => !IsParameterTypeSame(parameter.Convenience, parameter.Protocol)) || !_returnType.Convenience.Equals(_returnType.Protocol); } @@ -382,6 +385,11 @@ private ReturnTypeChain BuildReturnTypes() protocolToConvenience.Add(new ProtocolToConvenienceParameterConverter(protocolParameter, convenienceParameter, null)); } } + else if (protocolParameter != null) + { + // convenience parameter is null - such as CancellationToken in non-azure library + protocolToConvenience.Add(new ProtocolToConvenienceParameterConverter(protocolParameter, convenienceParameter, null)); + } } var accessibility = _restClientMethod.Accessibility | Virtual; if (generationInfo.IsConvenienceMethodInternal) @@ -590,7 +598,7 @@ public void AddRequestConditionHeaders(RequestConditionHeaders conditionHeaderFl public void AddRequestContext() { _orderedParameters.Add(new ParameterChain( - KnownParameters.CancellationTokenParameter, + Configuration.IsBranded ? KnownParameters.CancellationTokenParameter : null, // in non-azure libraries, convenience method no longer takes a `CancellationToken` parameter. ShouldRequestContextOptional() ? KnownParameters.RequestContext : KnownParameters.RequestContextRequired, KnownParameters.RequestContext)); } diff --git a/src/AutoRest.CSharp/LowLevel/Output/Samples/DpgOperationSample.cs b/src/AutoRest.CSharp/LowLevel/Output/Samples/DpgOperationSample.cs index e6c8704af0b..280ba45ca26 100644 --- a/src/AutoRest.CSharp/LowLevel/Output/Samples/DpgOperationSample.cs +++ b/src/AutoRest.CSharp/LowLevel/Output/Samples/DpgOperationSample.cs @@ -400,6 +400,7 @@ public static bool ShouldGenerateShortVersion(LowLevelClient client, LowLevelCli if (method.ConvenienceMethod is not null) { if (method.ConvenienceMethod.Signature.Parameters.Count == method.ProtocolMethodSignature.Parameters.Count - 1 && + method.ConvenienceMethod.Signature.Parameters.Count > 0 && !method.ConvenienceMethod.Signature.Parameters.Last().Type.Equals(typeof(CancellationToken))) { bool allEqual = true; diff --git a/test/UnbrandedProjects/Customized-TypeSpec/src/Generated/SuperClient.cs b/test/UnbrandedProjects/Customized-TypeSpec/src/Generated/SuperClient.cs index aa62b1658b3..0b522656755 100644 --- a/test/UnbrandedProjects/Customized-TypeSpec/src/Generated/SuperClient.cs +++ b/test/UnbrandedProjects/Customized-TypeSpec/src/Generated/SuperClient.cs @@ -5,7 +5,6 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; -using System.Threading; using System.Threading.Tasks; namespace CustomizedTypeSpec.Models @@ -107,18 +106,16 @@ public virtual ClientResult SayHi(string headParameter, string queryParameter, s /// The to use. /// The to use. /// The to use. - /// The cancellation token to use. /// , or is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> HelloAgainAsync(string p2, string p1, SuperRoundTripModel action, CancellationToken cancellationToken = default) + public virtual async Task> HelloAgainAsync(string p2, string p1, SuperRoundTripModel action) { Argument.AssertNotNullOrEmpty(p2, nameof(p2)); Argument.AssertNotNull(p1, nameof(p1)); Argument.AssertNotNull(action, nameof(action)); using BinaryContent content = action.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await HelloAgainAsync(p2, p1, content, options).ConfigureAwait(false); + ClientResult result = await HelloAgainAsync(p2, p1, content, null).ConfigureAwait(false); return ClientResult.FromValue(SuperRoundTripModel.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -126,18 +123,16 @@ public virtual async Task> HelloAgainAsync(str /// The to use. /// The to use. /// The to use. - /// The cancellation token to use. /// , or is null. /// is an empty string, and was expected to be non-empty. - public virtual ClientResult HelloAgain(string p2, string p1, SuperRoundTripModel action, CancellationToken cancellationToken = default) + public virtual ClientResult HelloAgain(string p2, string p1, SuperRoundTripModel action) { Argument.AssertNotNullOrEmpty(p2, nameof(p2)); Argument.AssertNotNull(p1, nameof(p1)); Argument.AssertNotNull(action, nameof(action)); using BinaryContent content = action.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = HelloAgain(p2, p1, content, options); + ClientResult result = HelloAgain(p2, p1, content, null); return ClientResult.FromValue(SuperRoundTripModel.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -151,7 +146,7 @@ public virtual ClientResult HelloAgain(string p2, string p1 /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -184,7 +179,7 @@ public virtual async Task HelloAgainAsync(string p2, string p1, Bi /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -264,20 +259,16 @@ public virtual ClientResult NoContentType(string p2, string p1, BinaryContent co } /// Return hi in demo2. - /// The cancellation token to use. - public virtual async Task> HelloDemo2Async(CancellationToken cancellationToken = default) + public virtual async Task> HelloDemo2Async() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await HelloDemo2Async(options).ConfigureAwait(false); + ClientResult result = await HelloDemo2Async(null).ConfigureAwait(false); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Return hi in demo2. - /// The cancellation token to use. - public virtual ClientResult HelloDemo2(CancellationToken cancellationToken = default) + public virtual ClientResult HelloDemo2() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = HelloDemo2(options); + ClientResult result = HelloDemo2(null); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -291,7 +282,7 @@ public virtual ClientResult HelloDemo2(CancellationToken cancellationToke /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -315,7 +306,7 @@ public virtual async Task HelloDemo2Async(RequestOptions options) /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -331,29 +322,25 @@ public virtual ClientResult HelloDemo2(RequestOptions options) /// Create with literal value. /// The to use. - /// The cancellation token to use. /// is null. - public virtual async Task> CreateLiteralAsync(Thing body, CancellationToken cancellationToken = default) + public virtual async Task> CreateLiteralAsync(Thing body) { Argument.AssertNotNull(body, nameof(body)); using BinaryContent content = body.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await CreateLiteralAsync(content, options).ConfigureAwait(false); + ClientResult result = await CreateLiteralAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Create with literal value. /// The to use. - /// The cancellation token to use. /// is null. - public virtual ClientResult CreateLiteral(Thing body, CancellationToken cancellationToken = default) + public virtual ClientResult CreateLiteral(Thing body) { Argument.AssertNotNull(body, nameof(body)); using BinaryContent content = body.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = CreateLiteral(content, options); + ClientResult result = CreateLiteral(content, null); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -367,7 +354,7 @@ public virtual ClientResult CreateLiteral(Thing body, CancellationToken c /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -395,7 +382,7 @@ public virtual async Task CreateLiteralAsync(BinaryContent content /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -414,20 +401,16 @@ public virtual ClientResult CreateLiteral(BinaryContent content, RequestOptions } /// Send literal parameters. - /// The cancellation token to use. - public virtual async Task> HelloLiteralAsync(CancellationToken cancellationToken = default) + public virtual async Task> HelloLiteralAsync() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await HelloLiteralAsync(options).ConfigureAwait(false); + ClientResult result = await HelloLiteralAsync(null).ConfigureAwait(false); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Send literal parameters. - /// The cancellation token to use. - public virtual ClientResult HelloLiteral(CancellationToken cancellationToken = default) + public virtual ClientResult HelloLiteral() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = HelloLiteral(options); + ClientResult result = HelloLiteral(null); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -441,7 +424,7 @@ public virtual ClientResult HelloLiteral(CancellationToken cancellationTo /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -465,7 +448,7 @@ public virtual async Task HelloLiteralAsync(RequestOptions options /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -481,21 +464,17 @@ public virtual ClientResult HelloLiteral(RequestOptions options) /// top level method. /// The to use. - /// The cancellation token to use. - public virtual async Task> TopActionAsync(DateTimeOffset action, CancellationToken cancellationToken = default) + public virtual async Task> TopActionAsync(DateTimeOffset action) { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await TopActionAsync(action, options).ConfigureAwait(false); + ClientResult result = await TopActionAsync(action, null).ConfigureAwait(false); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// top level method. /// The to use. - /// The cancellation token to use. - public virtual ClientResult TopAction(DateTimeOffset action, CancellationToken cancellationToken = default) + public virtual ClientResult TopAction(DateTimeOffset action) { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = TopAction(action, options); + ClientResult result = TopAction(action, null); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -509,7 +488,7 @@ public virtual ClientResult TopAction(DateTimeOffset action, Cancellation /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -534,7 +513,7 @@ public virtual async Task TopActionAsync(DateTimeOffset action, Re /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -635,29 +614,25 @@ public virtual ClientResult PatchAction(BinaryContent content, RequestOptions op /// body parameter without body decorator. /// A model with a few properties of literal types. - /// The cancellation token to use. /// is null. - public virtual async Task> AnonymousBodyAsync(Thing thing, CancellationToken cancellationToken = default) + public virtual async Task> AnonymousBodyAsync(Thing thing) { Argument.AssertNotNull(thing, nameof(thing)); using BinaryContent content = thing.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await AnonymousBodyAsync(content, options).ConfigureAwait(false); + ClientResult result = await AnonymousBodyAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// body parameter without body decorator. /// A model with a few properties of literal types. - /// The cancellation token to use. /// is null. - public virtual ClientResult AnonymousBody(Thing thing, CancellationToken cancellationToken = default) + public virtual ClientResult AnonymousBody(Thing thing) { Argument.AssertNotNull(thing, nameof(thing)); using BinaryContent content = thing.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = AnonymousBody(content, options); + ClientResult result = AnonymousBody(content, null); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -671,7 +646,7 @@ public virtual ClientResult AnonymousBody(Thing thing, CancellationToken /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -699,7 +674,7 @@ public virtual async Task AnonymousBodyAsync(BinaryContent content /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -719,29 +694,25 @@ public virtual ClientResult AnonymousBody(BinaryContent content, RequestOptions /// Model can have its friendly name. /// this is not a friendly model but with a friendly name. - /// The cancellation token to use. /// is null. - public virtual async Task> FriendlyModelAsync(SuperFriend superFriend, CancellationToken cancellationToken = default) + public virtual async Task> FriendlyModelAsync(SuperFriend superFriend) { Argument.AssertNotNull(superFriend, nameof(superFriend)); using BinaryContent content = superFriend.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await FriendlyModelAsync(content, options).ConfigureAwait(false); + ClientResult result = await FriendlyModelAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(SuperFriend.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Model can have its friendly name. /// this is not a friendly model but with a friendly name. - /// The cancellation token to use. /// is null. - public virtual ClientResult FriendlyModel(SuperFriend superFriend, CancellationToken cancellationToken = default) + public virtual ClientResult FriendlyModel(SuperFriend superFriend) { Argument.AssertNotNull(superFriend, nameof(superFriend)); using BinaryContent content = superFriend.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = FriendlyModel(content, options); + ClientResult result = FriendlyModel(content, null); return ClientResult.FromValue(SuperFriend.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -755,7 +726,7 @@ public virtual ClientResult FriendlyModel(SuperFriend superFriend, /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -783,7 +754,7 @@ public virtual async Task FriendlyModelAsync(BinaryContent content /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -842,30 +813,26 @@ public virtual ClientResult AddTimeHeader(RequestOptions options = null) /// parameter has string format. /// The to use. /// The to use. - /// The cancellation token to use. /// is null. - public virtual async Task StringFormatAsync(Guid subscriptionId, ModelWithFormat body, CancellationToken cancellationToken = default) + public virtual async Task StringFormatAsync(Guid subscriptionId, ModelWithFormat body) { Argument.AssertNotNull(body, nameof(body)); using BinaryContent content = body.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await StringFormatAsync(subscriptionId, content, options).ConfigureAwait(false); + ClientResult result = await StringFormatAsync(subscriptionId, content, null).ConfigureAwait(false); return result; } /// parameter has string format. /// The to use. /// The to use. - /// The cancellation token to use. /// is null. - public virtual ClientResult StringFormat(Guid subscriptionId, ModelWithFormat body, CancellationToken cancellationToken = default) + public virtual ClientResult StringFormat(Guid subscriptionId, ModelWithFormat body) { Argument.AssertNotNull(body, nameof(body)); using BinaryContent content = body.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = StringFormat(subscriptionId, content, options); + ClientResult result = StringFormat(subscriptionId, content, null); return result; } @@ -879,7 +846,7 @@ public virtual ClientResult StringFormat(Guid subscriptionId, ModelWithFormat bo /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -908,7 +875,7 @@ public virtual async Task StringFormatAsync(Guid subscriptionId, B /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -929,29 +896,25 @@ public virtual ClientResult StringFormat(Guid subscriptionId, BinaryContent cont /// Model can have its projected name. /// this is a model with a projected name. - /// The cancellation token to use. /// is null. - public virtual async Task> ProjectedNameModelAsync(ProjectedModel projectedModel, CancellationToken cancellationToken = default) + public virtual async Task> ProjectedNameModelAsync(ProjectedModel projectedModel) { Argument.AssertNotNull(projectedModel, nameof(projectedModel)); using BinaryContent content = projectedModel.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await ProjectedNameModelAsync(content, options).ConfigureAwait(false); + ClientResult result = await ProjectedNameModelAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(ProjectedModel.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Model can have its projected name. /// this is a model with a projected name. - /// The cancellation token to use. /// is null. - public virtual ClientResult ProjectedNameModel(ProjectedModel projectedModel, CancellationToken cancellationToken = default) + public virtual ClientResult ProjectedNameModel(ProjectedModel projectedModel) { Argument.AssertNotNull(projectedModel, nameof(projectedModel)); using BinaryContent content = projectedModel.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = ProjectedNameModel(content, options); + ClientResult result = ProjectedNameModel(content, null); return ClientResult.FromValue(ProjectedModel.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -965,7 +928,7 @@ public virtual ClientResult ProjectedNameModel(ProjectedModel pr /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -993,7 +956,7 @@ public virtual async Task ProjectedNameModelAsync(BinaryContent co /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -1012,20 +975,16 @@ public virtual ClientResult ProjectedNameModel(BinaryContent content, RequestOpt } /// return anonymous model. - /// The cancellation token to use. - public virtual async Task> ReturnsAnonymousModelAsync(CancellationToken cancellationToken = default) + public virtual async Task> ReturnsAnonymousModelAsync() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await ReturnsAnonymousModelAsync(options).ConfigureAwait(false); + ClientResult result = await ReturnsAnonymousModelAsync(null).ConfigureAwait(false); return ClientResult.FromValue(ReturnsAnonymousModelResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// return anonymous model. - /// The cancellation token to use. - public virtual ClientResult ReturnsAnonymousModel(CancellationToken cancellationToken = default) + public virtual ClientResult ReturnsAnonymousModel() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = ReturnsAnonymousModel(options); + ClientResult result = ReturnsAnonymousModel(null); return ClientResult.FromValue(ReturnsAnonymousModelResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -1039,7 +998,7 @@ public virtual ClientResult ReturnsAnonymousModel /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -1063,7 +1022,7 @@ public virtual async Task ReturnsAnonymousModelAsync(RequestOption /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -1117,29 +1076,25 @@ public virtual ClientResult GetUnknownValue(RequestOptions options) /// When set protocol false and convenient true, then the protocol method should be internal. /// The to use. - /// The cancellation token to use. /// is null. - public virtual async Task> InternalProtocolAsync(Thing body, CancellationToken cancellationToken = default) + public virtual async Task> InternalProtocolAsync(Thing body) { Argument.AssertNotNull(body, nameof(body)); using BinaryContent content = body.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await InternalProtocolAsync(content, options).ConfigureAwait(false); + ClientResult result = await InternalProtocolAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// When set protocol false and convenient true, then the protocol method should be internal. /// The to use. - /// The cancellation token to use. /// is null. - public virtual ClientResult InternalProtocol(Thing body, CancellationToken cancellationToken = default) + public virtual ClientResult InternalProtocol(Thing body) { Argument.AssertNotNull(body, nameof(body)); using BinaryContent content = body.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = InternalProtocol(content, options); + ClientResult result = InternalProtocol(content, null); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -1190,20 +1145,16 @@ internal virtual ClientResult InternalProtocol(BinaryContent content, RequestOpt } /// When set protocol false and convenient true, the convenient method should be generated even it has the same signature as protocol one. - /// The cancellation token to use. - public virtual async Task StillConvenientValueAsync(CancellationToken cancellationToken = default) + public virtual async Task StillConvenientValueAsync() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await StillConvenientAsync(options).ConfigureAwait(false); + ClientResult result = await StillConvenientAsync(null).ConfigureAwait(false); return result; } /// When set protocol false and convenient true, the convenient method should be generated even it has the same signature as protocol one. - /// The cancellation token to use. - public virtual ClientResult StillConvenientValue(CancellationToken cancellationToken = default) + public virtual ClientResult StillConvenientValue() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = StillConvenient(options); + ClientResult result = StillConvenient(null); return result; } @@ -1674,17 +1625,6 @@ internal PipelineMessage CreateHeadAsBooleanRequest(string id, RequestOptions op return message; } - private static RequestOptions DefaultRequestContext = new RequestOptions(); - internal static RequestOptions FromCancellationToken(CancellationToken cancellationToken = default) - { - if (!cancellationToken.CanBeCanceled) - { - return DefaultRequestContext; - } - - return new RequestOptions() { CancellationToken = cancellationToken }; - } - private static PipelineMessageClassifier _pipelineMessageClassifier200; private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); private static PipelineMessageClassifier _pipelineMessageClassifier204; diff --git a/test/UnbrandedProjects/NoTest-TypeSpec/src/Generated/NoTestTypeSpecClient.cs b/test/UnbrandedProjects/NoTest-TypeSpec/src/Generated/NoTestTypeSpecClient.cs index 78b463e494d..157c61000f9 100644 --- a/test/UnbrandedProjects/NoTest-TypeSpec/src/Generated/NoTestTypeSpecClient.cs +++ b/test/UnbrandedProjects/NoTest-TypeSpec/src/Generated/NoTestTypeSpecClient.cs @@ -5,7 +5,6 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; -using System.Threading; using System.Threading.Tasks; using NoTestTypeSpec.Models; @@ -56,15 +55,13 @@ public NoTestTypeSpecClient(Uri endpoint, ApiKeyCredential credential, NoTestTyp /// The to use. /// The to use. /// The to use. - /// The cancellation token to use. /// or is null. - public virtual async Task> SayHiAsync(string headParameter, string queryParameter, string optionalQuery = null, CancellationToken cancellationToken = default) + public virtual async Task> SayHiAsync(string headParameter, string queryParameter, string optionalQuery = null) { Argument.AssertNotNull(headParameter, nameof(headParameter)); Argument.AssertNotNull(queryParameter, nameof(queryParameter)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await SayHiAsync(headParameter, queryParameter, optionalQuery, options).ConfigureAwait(false); + ClientResult result = await SayHiAsync(headParameter, queryParameter, optionalQuery, null).ConfigureAwait(false); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -72,15 +69,13 @@ public virtual async Task> SayHiAsync(string headParameter, /// The to use. /// The to use. /// The to use. - /// The cancellation token to use. /// or is null. - public virtual ClientResult SayHi(string headParameter, string queryParameter, string optionalQuery = null, CancellationToken cancellationToken = default) + public virtual ClientResult SayHi(string headParameter, string queryParameter, string optionalQuery = null) { Argument.AssertNotNull(headParameter, nameof(headParameter)); Argument.AssertNotNull(queryParameter, nameof(queryParameter)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = SayHi(headParameter, queryParameter, optionalQuery, options); + ClientResult result = SayHi(headParameter, queryParameter, optionalQuery, null); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -94,7 +89,7 @@ public virtual ClientResult SayHi(string headParameter, string queryParam /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -125,7 +120,7 @@ public virtual async Task SayHiAsync(string headParameter, string /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -170,17 +165,6 @@ internal PipelineMessage CreateSayHiRequest(string headParameter, string queryPa return message; } - private static RequestOptions DefaultRequestContext = new RequestOptions(); - internal static RequestOptions FromCancellationToken(CancellationToken cancellationToken = default) - { - if (!cancellationToken.CanBeCanceled) - { - return DefaultRequestContext; - } - - return new RequestOptions() { CancellationToken = cancellationToken }; - } - private static PipelineMessageClassifier _pipelineMessageClassifier200; private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); } diff --git a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/AudioTranscriptions.cs b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/AudioTranscriptions.cs index d0b80869e6e..c15269ca56a 100644 --- a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/AudioTranscriptions.cs +++ b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/AudioTranscriptions.cs @@ -5,7 +5,6 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; -using System.Threading; using System.Threading.Tasks; using OpenAI.Models; @@ -42,29 +41,25 @@ internal AudioTranscriptions(ClientPipeline pipeline, ApiKeyCredential keyCreden /// Transcribes audio into the input language. /// The to use. - /// The cancellation token to use. /// is null. - public virtual async Task> CreateAsync(CreateTranscriptionRequest audio, CancellationToken cancellationToken = default) + public virtual async Task> CreateAsync(CreateTranscriptionRequest audio) { Argument.AssertNotNull(audio, nameof(audio)); using BinaryContent content = audio.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await CreateAsync(content, options).ConfigureAwait(false); + ClientResult result = await CreateAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(CreateTranscriptionResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Transcribes audio into the input language. /// The to use. - /// The cancellation token to use. /// is null. - public virtual ClientResult Create(CreateTranscriptionRequest audio, CancellationToken cancellationToken = default) + public virtual ClientResult Create(CreateTranscriptionRequest audio) { Argument.AssertNotNull(audio, nameof(audio)); using BinaryContent content = audio.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Create(content, options); + ClientResult result = Create(content, null); return ClientResult.FromValue(CreateTranscriptionResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -78,7 +73,7 @@ public virtual ClientResult Create(CreateTranscript /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -106,7 +101,7 @@ public virtual async Task CreateAsync(BinaryContent content, Reque /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -144,17 +139,6 @@ internal PipelineMessage CreateCreateRequest(BinaryContent content, RequestOptio return message; } - private static RequestOptions DefaultRequestContext = new RequestOptions(); - internal static RequestOptions FromCancellationToken(CancellationToken cancellationToken = default) - { - if (!cancellationToken.CanBeCanceled) - { - return DefaultRequestContext; - } - - return new RequestOptions() { CancellationToken = cancellationToken }; - } - private static PipelineMessageClassifier _pipelineMessageClassifier200; private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); } diff --git a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/AudioTranslations.cs b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/AudioTranslations.cs index f18d8ab7cca..00db8a54652 100644 --- a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/AudioTranslations.cs +++ b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/AudioTranslations.cs @@ -5,7 +5,6 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; -using System.Threading; using System.Threading.Tasks; using OpenAI.Models; @@ -42,29 +41,25 @@ internal AudioTranslations(ClientPipeline pipeline, ApiKeyCredential keyCredenti /// Transcribes audio into the input language. /// The to use. - /// The cancellation token to use. /// is null. - public virtual async Task> CreateAsync(CreateTranslationRequest audio, CancellationToken cancellationToken = default) + public virtual async Task> CreateAsync(CreateTranslationRequest audio) { Argument.AssertNotNull(audio, nameof(audio)); using BinaryContent content = audio.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await CreateAsync(content, options).ConfigureAwait(false); + ClientResult result = await CreateAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(CreateTranslationResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Transcribes audio into the input language. /// The to use. - /// The cancellation token to use. /// is null. - public virtual ClientResult Create(CreateTranslationRequest audio, CancellationToken cancellationToken = default) + public virtual ClientResult Create(CreateTranslationRequest audio) { Argument.AssertNotNull(audio, nameof(audio)); using BinaryContent content = audio.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Create(content, options); + ClientResult result = Create(content, null); return ClientResult.FromValue(CreateTranslationResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -78,7 +73,7 @@ public virtual ClientResult Create(CreateTranslationR /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -106,7 +101,7 @@ public virtual async Task CreateAsync(BinaryContent content, Reque /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -144,17 +139,6 @@ internal PipelineMessage CreateCreateRequest(BinaryContent content, RequestOptio return message; } - private static RequestOptions DefaultRequestContext = new RequestOptions(); - internal static RequestOptions FromCancellationToken(CancellationToken cancellationToken = default) - { - if (!cancellationToken.CanBeCanceled) - { - return DefaultRequestContext; - } - - return new RequestOptions() { CancellationToken = cancellationToken }; - } - private static PipelineMessageClassifier _pipelineMessageClassifier200; private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); } diff --git a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/ChatCompletions.cs b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/ChatCompletions.cs index 0a786dba2b5..8fd8a4b345d 100644 --- a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/ChatCompletions.cs +++ b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/ChatCompletions.cs @@ -5,7 +5,6 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; -using System.Threading; using System.Threading.Tasks; using OpenAI.Models; @@ -41,28 +40,24 @@ internal ChatCompletions(ClientPipeline pipeline, ApiKeyCredential keyCredential } /// The to use. - /// The cancellation token to use. /// is null. - public virtual async Task> CreateAsync(CreateChatCompletionRequest createChatCompletionRequest, CancellationToken cancellationToken = default) + public virtual async Task> CreateAsync(CreateChatCompletionRequest createChatCompletionRequest) { Argument.AssertNotNull(createChatCompletionRequest, nameof(createChatCompletionRequest)); using BinaryContent content = createChatCompletionRequest.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await CreateAsync(content, options).ConfigureAwait(false); + ClientResult result = await CreateAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(CreateChatCompletionResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// The to use. - /// The cancellation token to use. /// is null. - public virtual ClientResult Create(CreateChatCompletionRequest createChatCompletionRequest, CancellationToken cancellationToken = default) + public virtual ClientResult Create(CreateChatCompletionRequest createChatCompletionRequest) { Argument.AssertNotNull(createChatCompletionRequest, nameof(createChatCompletionRequest)); using BinaryContent content = createChatCompletionRequest.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Create(content, options); + ClientResult result = Create(content, null); return ClientResult.FromValue(CreateChatCompletionResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -76,7 +71,7 @@ public virtual ClientResult Create(CreateChatCompl /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -104,7 +99,7 @@ public virtual async Task CreateAsync(BinaryContent content, Reque /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -142,17 +137,6 @@ internal PipelineMessage CreateCreateRequest(BinaryContent content, RequestOptio return message; } - private static RequestOptions DefaultRequestContext = new RequestOptions(); - internal static RequestOptions FromCancellationToken(CancellationToken cancellationToken = default) - { - if (!cancellationToken.CanBeCanceled) - { - return DefaultRequestContext; - } - - return new RequestOptions() { CancellationToken = cancellationToken }; - } - private static PipelineMessageClassifier _pipelineMessageClassifier200; private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); } diff --git a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Completions.cs b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Completions.cs index 1042d5ada68..95c01d1c40f 100644 --- a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Completions.cs +++ b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Completions.cs @@ -5,7 +5,6 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; -using System.Threading; using System.Threading.Tasks; using OpenAI.Models; @@ -41,28 +40,24 @@ internal Completions(ClientPipeline pipeline, ApiKeyCredential keyCredential, Ur } /// The to use. - /// The cancellation token to use. /// is null. - public virtual async Task> CreateAsync(CreateCompletionRequest createCompletionRequest, CancellationToken cancellationToken = default) + public virtual async Task> CreateAsync(CreateCompletionRequest createCompletionRequest) { Argument.AssertNotNull(createCompletionRequest, nameof(createCompletionRequest)); using BinaryContent content = createCompletionRequest.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await CreateAsync(content, options).ConfigureAwait(false); + ClientResult result = await CreateAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(CreateCompletionResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// The to use. - /// The cancellation token to use. /// is null. - public virtual ClientResult Create(CreateCompletionRequest createCompletionRequest, CancellationToken cancellationToken = default) + public virtual ClientResult Create(CreateCompletionRequest createCompletionRequest) { Argument.AssertNotNull(createCompletionRequest, nameof(createCompletionRequest)); using BinaryContent content = createCompletionRequest.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Create(content, options); + ClientResult result = Create(content, null); return ClientResult.FromValue(CreateCompletionResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -76,7 +71,7 @@ public virtual ClientResult Create(CreateCompletionReq /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -104,7 +99,7 @@ public virtual async Task CreateAsync(BinaryContent content, Reque /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -142,17 +137,6 @@ internal PipelineMessage CreateCreateRequest(BinaryContent content, RequestOptio return message; } - private static RequestOptions DefaultRequestContext = new RequestOptions(); - internal static RequestOptions FromCancellationToken(CancellationToken cancellationToken = default) - { - if (!cancellationToken.CanBeCanceled) - { - return DefaultRequestContext; - } - - return new RequestOptions() { CancellationToken = cancellationToken }; - } - private static PipelineMessageClassifier _pipelineMessageClassifier200; private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); } diff --git a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Edits.cs b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Edits.cs index 824ecfe05aa..cf30ef82d8b 100644 --- a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Edits.cs +++ b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Edits.cs @@ -5,7 +5,6 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; -using System.Threading; using System.Threading.Tasks; using OpenAI.Models; @@ -41,30 +40,26 @@ internal Edits(ClientPipeline pipeline, ApiKeyCredential keyCredential, Uri endp } /// The to use. - /// The cancellation token to use. /// is null. [Obsolete("deprecated")] - public virtual async Task> CreateAsync(CreateEditRequest edit, CancellationToken cancellationToken = default) + public virtual async Task> CreateAsync(CreateEditRequest edit) { Argument.AssertNotNull(edit, nameof(edit)); using BinaryContent content = edit.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await CreateAsync(content, options).ConfigureAwait(false); + ClientResult result = await CreateAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(CreateEditResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// The to use. - /// The cancellation token to use. /// is null. [Obsolete("deprecated")] - public virtual ClientResult Create(CreateEditRequest edit, CancellationToken cancellationToken = default) + public virtual ClientResult Create(CreateEditRequest edit) { Argument.AssertNotNull(edit, nameof(edit)); using BinaryContent content = edit.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Create(content, options); + ClientResult result = Create(content, null); return ClientResult.FromValue(CreateEditResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -78,7 +73,7 @@ public virtual ClientResult Create(CreateEditRequest edit, C /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -107,7 +102,7 @@ public virtual async Task CreateAsync(BinaryContent content, Reque /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -146,17 +141,6 @@ internal PipelineMessage CreateCreateRequest(BinaryContent content, RequestOptio return message; } - private static RequestOptions DefaultRequestContext = new RequestOptions(); - internal static RequestOptions FromCancellationToken(CancellationToken cancellationToken = default) - { - if (!cancellationToken.CanBeCanceled) - { - return DefaultRequestContext; - } - - return new RequestOptions() { CancellationToken = cancellationToken }; - } - private static PipelineMessageClassifier _pipelineMessageClassifier200; private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); } diff --git a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Embeddings.cs b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Embeddings.cs index c0359f6ef45..9c04b76140f 100644 --- a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Embeddings.cs +++ b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Embeddings.cs @@ -5,7 +5,6 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; -using System.Threading; using System.Threading.Tasks; using OpenAI.Models; @@ -42,29 +41,25 @@ internal Embeddings(ClientPipeline pipeline, ApiKeyCredential keyCredential, Uri /// Creates an embedding vector representing the input text. /// The to use. - /// The cancellation token to use. /// is null. - public virtual async Task> CreateAsync(CreateEmbeddingRequest embedding, CancellationToken cancellationToken = default) + public virtual async Task> CreateAsync(CreateEmbeddingRequest embedding) { Argument.AssertNotNull(embedding, nameof(embedding)); using BinaryContent content = embedding.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await CreateAsync(content, options).ConfigureAwait(false); + ClientResult result = await CreateAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(CreateEmbeddingResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Creates an embedding vector representing the input text. /// The to use. - /// The cancellation token to use. /// is null. - public virtual ClientResult Create(CreateEmbeddingRequest embedding, CancellationToken cancellationToken = default) + public virtual ClientResult Create(CreateEmbeddingRequest embedding) { Argument.AssertNotNull(embedding, nameof(embedding)); using BinaryContent content = embedding.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Create(content, options); + ClientResult result = Create(content, null); return ClientResult.FromValue(CreateEmbeddingResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -78,7 +73,7 @@ public virtual ClientResult Create(CreateEmbeddingReque /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -106,7 +101,7 @@ public virtual async Task CreateAsync(BinaryContent content, Reque /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -144,17 +139,6 @@ internal PipelineMessage CreateCreateRequest(BinaryContent content, RequestOptio return message; } - private static RequestOptions DefaultRequestContext = new RequestOptions(); - internal static RequestOptions FromCancellationToken(CancellationToken cancellationToken = default) - { - if (!cancellationToken.CanBeCanceled) - { - return DefaultRequestContext; - } - - return new RequestOptions() { CancellationToken = cancellationToken }; - } - private static PipelineMessageClassifier _pipelineMessageClassifier200; private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); } diff --git a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Files.cs b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Files.cs index ed2e928d5f5..f381e78003b 100644 --- a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Files.cs +++ b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Files.cs @@ -5,7 +5,6 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; -using System.Threading; using System.Threading.Tasks; using OpenAI.Models; @@ -41,20 +40,16 @@ internal Files(ClientPipeline pipeline, ApiKeyCredential keyCredential, Uri endp } /// Returns a list of files that belong to the user's organization. - /// The cancellation token to use. - public virtual async Task> GetFilesAsync(CancellationToken cancellationToken = default) + public virtual async Task> GetFilesAsync() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await GetFilesAsync(options).ConfigureAwait(false); + ClientResult result = await GetFilesAsync(null).ConfigureAwait(false); return ClientResult.FromValue(ListFilesResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Returns a list of files that belong to the user's organization. - /// The cancellation token to use. - public virtual ClientResult GetFiles(CancellationToken cancellationToken = default) + public virtual ClientResult GetFiles() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = GetFiles(options); + ClientResult result = GetFiles(null); return ClientResult.FromValue(ListFilesResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -68,7 +63,7 @@ public virtual ClientResult GetFiles(CancellationToken cancel /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -92,7 +87,7 @@ public virtual async Task GetFilesAsync(RequestOptions options) /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -108,29 +103,25 @@ public virtual ClientResult GetFiles(RequestOptions options) /// Returns a list of files that belong to the user's organization. /// The to use. - /// The cancellation token to use. /// is null. - public virtual async Task> CreateAsync(CreateFileRequest file, CancellationToken cancellationToken = default) + public virtual async Task> CreateAsync(CreateFileRequest file) { Argument.AssertNotNull(file, nameof(file)); using BinaryContent content = file.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await CreateAsync(content, options).ConfigureAwait(false); + ClientResult result = await CreateAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(OpenAIFile.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Returns a list of files that belong to the user's organization. /// The to use. - /// The cancellation token to use. /// is null. - public virtual ClientResult Create(CreateFileRequest file, CancellationToken cancellationToken = default) + public virtual ClientResult Create(CreateFileRequest file) { Argument.AssertNotNull(file, nameof(file)); using BinaryContent content = file.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Create(content, options); + ClientResult result = Create(content, null); return ClientResult.FromValue(OpenAIFile.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -144,7 +135,7 @@ public virtual ClientResult Create(CreateFileRequest file, Cancellat /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -172,7 +163,7 @@ public virtual async Task CreateAsync(BinaryContent content, Reque /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -192,29 +183,25 @@ public virtual ClientResult Create(BinaryContent content, RequestOptions options /// Returns information about a specific file. /// The ID of the file to use for this request. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> RetrieveAsync(string fileId, CancellationToken cancellationToken = default) + public virtual async Task> RetrieveAsync(string fileId) { Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await RetrieveAsync(fileId, options).ConfigureAwait(false); + ClientResult result = await RetrieveAsync(fileId, null).ConfigureAwait(false); return ClientResult.FromValue(OpenAIFile.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Returns information about a specific file. /// The ID of the file to use for this request. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual ClientResult Retrieve(string fileId, CancellationToken cancellationToken = default) + public virtual ClientResult Retrieve(string fileId) { Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Retrieve(fileId, options); + ClientResult result = Retrieve(fileId, null); return ClientResult.FromValue(OpenAIFile.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -228,7 +215,7 @@ public virtual ClientResult Retrieve(string fileId, CancellationToke /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -257,7 +244,7 @@ public virtual async Task RetrieveAsync(string fileId, RequestOpti /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -278,29 +265,25 @@ public virtual ClientResult Retrieve(string fileId, RequestOptions options) /// Delete a file. /// The ID of the file to use for this request. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> DeleteAsync(string fileId, CancellationToken cancellationToken = default) + public virtual async Task> DeleteAsync(string fileId) { Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await DeleteAsync(fileId, options).ConfigureAwait(false); + ClientResult result = await DeleteAsync(fileId, null).ConfigureAwait(false); return ClientResult.FromValue(DeleteFileResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Delete a file. /// The ID of the file to use for this request. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual ClientResult Delete(string fileId, CancellationToken cancellationToken = default) + public virtual ClientResult Delete(string fileId) { Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Delete(fileId, options); + ClientResult result = Delete(fileId, null); return ClientResult.FromValue(DeleteFileResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -314,7 +297,7 @@ public virtual ClientResult Delete(string fileId, Cancellati /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -343,7 +326,7 @@ public virtual async Task DeleteAsync(string fileId, RequestOption /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -364,29 +347,25 @@ public virtual ClientResult Delete(string fileId, RequestOptions options) /// Returns the contents of the specified file. /// The ID of the file to use for this request. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> DownloadAsync(string fileId, CancellationToken cancellationToken = default) + public virtual async Task> DownloadAsync(string fileId) { Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await DownloadAsync(fileId, options).ConfigureAwait(false); + ClientResult result = await DownloadAsync(fileId, null).ConfigureAwait(false); return ClientResult.FromValue(result.GetRawResponse().Content.ToObjectFromJson(), result.GetRawResponse()); } /// Returns the contents of the specified file. /// The ID of the file to use for this request. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual ClientResult Download(string fileId, CancellationToken cancellationToken = default) + public virtual ClientResult Download(string fileId) { Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Download(fileId, options); + ClientResult result = Download(fileId, null); return ClientResult.FromValue(result.GetRawResponse().Content.ToObjectFromJson(), result.GetRawResponse()); } @@ -400,7 +379,7 @@ public virtual ClientResult Download(string fileId, CancellationToken ca /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -429,7 +408,7 @@ public virtual async Task DownloadAsync(string fileId, RequestOpti /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -544,17 +523,6 @@ internal PipelineMessage CreateDownloadRequest(string fileId, RequestOptions opt return message; } - private static RequestOptions DefaultRequestContext = new RequestOptions(); - internal static RequestOptions FromCancellationToken(CancellationToken cancellationToken = default) - { - if (!cancellationToken.CanBeCanceled) - { - return DefaultRequestContext; - } - - return new RequestOptions() { CancellationToken = cancellationToken }; - } - private static PipelineMessageClassifier _pipelineMessageClassifier200; private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); } diff --git a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/FineTunes.cs b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/FineTunes.cs index d15e70a697b..3f21f3fd521 100644 --- a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/FineTunes.cs +++ b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/FineTunes.cs @@ -5,7 +5,6 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; -using System.Threading; using System.Threading.Tasks; using OpenAI.Models; @@ -48,16 +47,14 @@ internal FineTunes(ClientPipeline pipeline, ApiKeyCredential keyCredential, Uri /// [Learn more about fine-tuning](/docs/guides/legacy-fine-tuning) /// /// The to use. - /// The cancellation token to use. /// is null. [Obsolete("deprecated")] - public virtual async Task> CreateAsync(CreateFineTuneRequest fineTune, CancellationToken cancellationToken = default) + public virtual async Task> CreateAsync(CreateFineTuneRequest fineTune) { Argument.AssertNotNull(fineTune, nameof(fineTune)); using BinaryContent content = fineTune.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await CreateAsync(content, options).ConfigureAwait(false); + ClientResult result = await CreateAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(FineTune.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -69,16 +66,14 @@ public virtual async Task> CreateAsync(CreateFineTuneRequ /// [Learn more about fine-tuning](/docs/guides/legacy-fine-tuning) /// /// The to use. - /// The cancellation token to use. /// is null. [Obsolete("deprecated")] - public virtual ClientResult Create(CreateFineTuneRequest fineTune, CancellationToken cancellationToken = default) + public virtual ClientResult Create(CreateFineTuneRequest fineTune) { Argument.AssertNotNull(fineTune, nameof(fineTune)); using BinaryContent content = fineTune.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Create(content, options); + ClientResult result = Create(content, null); return ClientResult.FromValue(FineTune.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -96,7 +91,7 @@ public virtual ClientResult Create(CreateFineTuneRequest fineTune, Can /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -129,7 +124,7 @@ public virtual async Task CreateAsync(BinaryContent content, Reque /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -149,22 +144,18 @@ public virtual ClientResult Create(BinaryContent content, RequestOptions options } /// List your organization's fine-tuning jobs. - /// The cancellation token to use. [Obsolete("deprecated")] - public virtual async Task> GetFineTunesAsync(CancellationToken cancellationToken = default) + public virtual async Task> GetFineTunesAsync() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await GetFineTunesAsync(options).ConfigureAwait(false); + ClientResult result = await GetFineTunesAsync(null).ConfigureAwait(false); return ClientResult.FromValue(ListFineTunesResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// List your organization's fine-tuning jobs. - /// The cancellation token to use. [Obsolete("deprecated")] - public virtual ClientResult GetFineTunes(CancellationToken cancellationToken = default) + public virtual ClientResult GetFineTunes() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = GetFineTunes(options); + ClientResult result = GetFineTunes(null); return ClientResult.FromValue(ListFineTunesResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -178,7 +169,7 @@ public virtual ClientResult GetFineTunes(CancellationToke /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -203,7 +194,7 @@ public virtual async Task GetFineTunesAsync(RequestOptions options /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -224,16 +215,14 @@ public virtual ClientResult GetFineTunes(RequestOptions options) /// [Learn more about fine-tuning](/docs/guides/legacy-fine-tuning) /// /// The ID of the fine-tune job. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. [Obsolete("deprecated")] - public virtual async Task> RetrieveAsync(string fineTuneId, CancellationToken cancellationToken = default) + public virtual async Task> RetrieveAsync(string fineTuneId) { Argument.AssertNotNullOrEmpty(fineTuneId, nameof(fineTuneId)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await RetrieveAsync(fineTuneId, options).ConfigureAwait(false); + ClientResult result = await RetrieveAsync(fineTuneId, null).ConfigureAwait(false); return ClientResult.FromValue(FineTune.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -243,16 +232,14 @@ public virtual async Task> RetrieveAsync(string fineTuneI /// [Learn more about fine-tuning](/docs/guides/legacy-fine-tuning) /// /// The ID of the fine-tune job. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. [Obsolete("deprecated")] - public virtual ClientResult Retrieve(string fineTuneId, CancellationToken cancellationToken = default) + public virtual ClientResult Retrieve(string fineTuneId) { Argument.AssertNotNullOrEmpty(fineTuneId, nameof(fineTuneId)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Retrieve(fineTuneId, options); + ClientResult result = Retrieve(fineTuneId, null); return ClientResult.FromValue(FineTune.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -268,7 +255,7 @@ public virtual ClientResult Retrieve(string fineTuneId, CancellationTo /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -300,7 +287,7 @@ public virtual async Task RetrieveAsync(string fineTuneId, Request /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -331,16 +318,14 @@ public virtual ClientResult Retrieve(string fineTuneId, RequestOptions options) /// /// If set to false, only events generated so far will be returned. /// - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. [Obsolete("deprecated")] - public virtual async Task> GetEventsAsync(string fineTuneId, bool? stream = null, CancellationToken cancellationToken = default) + public virtual async Task> GetEventsAsync(string fineTuneId, bool? stream = null) { Argument.AssertNotNullOrEmpty(fineTuneId, nameof(fineTuneId)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await GetEventsAsync(fineTuneId, stream, options).ConfigureAwait(false); + ClientResult result = await GetEventsAsync(fineTuneId, stream, null).ConfigureAwait(false); return ClientResult.FromValue(ListFineTuneEventsResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -355,16 +340,14 @@ public virtual async Task> GetEventsAsy /// /// If set to false, only events generated so far will be returned. /// - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. [Obsolete("deprecated")] - public virtual ClientResult GetEvents(string fineTuneId, bool? stream = null, CancellationToken cancellationToken = default) + public virtual ClientResult GetEvents(string fineTuneId, bool? stream = null) { Argument.AssertNotNullOrEmpty(fineTuneId, nameof(fineTuneId)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = GetEvents(fineTuneId, stream, options); + ClientResult result = GetEvents(fineTuneId, stream, null); return ClientResult.FromValue(ListFineTuneEventsResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -378,7 +361,7 @@ public virtual ClientResult GetEvents(string fineTun /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -417,7 +400,7 @@ public virtual async Task GetEventsAsync(string fineTuneId, bool? /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -448,31 +431,27 @@ public virtual ClientResult GetEvents(string fineTuneId, bool? stream, RequestOp /// Immediately cancel a fine-tune job. /// The ID of the fine-tune job to cancel. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. [Obsolete("deprecated")] - public virtual async Task> CancelAsync(string fineTuneId, CancellationToken cancellationToken = default) + public virtual async Task> CancelAsync(string fineTuneId) { Argument.AssertNotNullOrEmpty(fineTuneId, nameof(fineTuneId)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await CancelAsync(fineTuneId, options).ConfigureAwait(false); + ClientResult result = await CancelAsync(fineTuneId, null).ConfigureAwait(false); return ClientResult.FromValue(FineTune.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Immediately cancel a fine-tune job. /// The ID of the fine-tune job to cancel. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. [Obsolete("deprecated")] - public virtual ClientResult Cancel(string fineTuneId, CancellationToken cancellationToken = default) + public virtual ClientResult Cancel(string fineTuneId) { Argument.AssertNotNullOrEmpty(fineTuneId, nameof(fineTuneId)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Cancel(fineTuneId, options); + ClientResult result = Cancel(fineTuneId, null); return ClientResult.FromValue(FineTune.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -486,7 +465,7 @@ public virtual ClientResult Cancel(string fineTuneId, CancellationToke /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -516,7 +495,7 @@ public virtual async Task CancelAsync(string fineTuneId, RequestOp /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -637,17 +616,6 @@ internal PipelineMessage CreateCancelRequest(string fineTuneId, RequestOptions o return message; } - private static RequestOptions DefaultRequestContext = new RequestOptions(); - internal static RequestOptions FromCancellationToken(CancellationToken cancellationToken = default) - { - if (!cancellationToken.CanBeCanceled) - { - return DefaultRequestContext; - } - - return new RequestOptions() { CancellationToken = cancellationToken }; - } - private static PipelineMessageClassifier _pipelineMessageClassifier200; private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); } diff --git a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/FineTuningJobs.cs b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/FineTuningJobs.cs index 2ccd8d6accd..6b9db4d5658 100644 --- a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/FineTuningJobs.cs +++ b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/FineTuningJobs.cs @@ -5,7 +5,6 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; -using System.Threading; using System.Threading.Tasks; using OpenAI.Models; @@ -49,15 +48,13 @@ internal FineTuningJobs(ClientPipeline pipeline, ApiKeyCredential keyCredential, /// [Learn more about fine-tuning](/docs/guides/fine-tuning) /// /// The to use. - /// The cancellation token to use. /// is null. - public virtual async Task> CreateAsync(CreateFineTuningJobRequest job, CancellationToken cancellationToken = default) + public virtual async Task> CreateAsync(CreateFineTuningJobRequest job) { Argument.AssertNotNull(job, nameof(job)); using BinaryContent content = job.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await CreateAsync(content, options).ConfigureAwait(false); + ClientResult result = await CreateAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(FineTuningJob.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -70,15 +67,13 @@ public virtual async Task> CreateAsync(CreateFineTun /// [Learn more about fine-tuning](/docs/guides/fine-tuning) /// /// The to use. - /// The cancellation token to use. /// is null. - public virtual ClientResult Create(CreateFineTuningJobRequest job, CancellationToken cancellationToken = default) + public virtual ClientResult Create(CreateFineTuningJobRequest job) { Argument.AssertNotNull(job, nameof(job)); using BinaryContent content = job.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Create(content, options); + ClientResult result = Create(content, null); return ClientResult.FromValue(FineTuningJob.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -97,7 +92,7 @@ public virtual ClientResult Create(CreateFineTuningJobRequest job /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -130,7 +125,7 @@ public virtual async Task CreateAsync(BinaryContent content, Reque /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -150,21 +145,17 @@ public virtual ClientResult Create(BinaryContent content, RequestOptions options /// Identifier for the last job from the previous pagination request. /// Number of fine-tuning jobs to retrieve. - /// The cancellation token to use. - public virtual async Task> GetPaginatedsAsync(string after = null, long? limit = null, CancellationToken cancellationToken = default) + public virtual async Task> GetPaginatedsAsync(string after = null, long? limit = null) { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await GetPaginatedsAsync(after, limit, options).ConfigureAwait(false); + ClientResult result = await GetPaginatedsAsync(after, limit, null).ConfigureAwait(false); return ClientResult.FromValue(ListPaginatedFineTuningJobsResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Identifier for the last job from the previous pagination request. /// Number of fine-tuning jobs to retrieve. - /// The cancellation token to use. - public virtual ClientResult GetPaginateds(string after = null, long? limit = null, CancellationToken cancellationToken = default) + public virtual ClientResult GetPaginateds(string after = null, long? limit = null) { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = GetPaginateds(after, limit, options); + ClientResult result = GetPaginateds(after, limit, null); return ClientResult.FromValue(ListPaginatedFineTuningJobsResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -178,7 +169,7 @@ public virtual ClientResult GetPaginateds(s /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -204,7 +195,7 @@ public virtual async Task GetPaginatedsAsync(string after, long? l /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -226,15 +217,13 @@ public virtual ClientResult GetPaginateds(string after, long? limit, RequestOpti /// [Learn more about fine-tuning](/docs/guides/fine-tuning) /// /// The to use. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> RetrieveAsync(string fineTuningJobId, CancellationToken cancellationToken = default) + public virtual async Task> RetrieveAsync(string fineTuningJobId) { Argument.AssertNotNullOrEmpty(fineTuningJobId, nameof(fineTuningJobId)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await RetrieveAsync(fineTuningJobId, options).ConfigureAwait(false); + ClientResult result = await RetrieveAsync(fineTuningJobId, null).ConfigureAwait(false); return ClientResult.FromValue(FineTuningJob.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -244,15 +233,13 @@ public virtual async Task> RetrieveAsync(string fine /// [Learn more about fine-tuning](/docs/guides/fine-tuning) /// /// The to use. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual ClientResult Retrieve(string fineTuningJobId, CancellationToken cancellationToken = default) + public virtual ClientResult Retrieve(string fineTuningJobId) { Argument.AssertNotNullOrEmpty(fineTuningJobId, nameof(fineTuningJobId)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Retrieve(fineTuningJobId, options); + ClientResult result = Retrieve(fineTuningJobId, null); return ClientResult.FromValue(FineTuningJob.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -268,7 +255,7 @@ public virtual ClientResult Retrieve(string fineTuningJobId, Canc /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -299,7 +286,7 @@ public virtual async Task RetrieveAsync(string fineTuningJobId, Re /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -322,15 +309,13 @@ public virtual ClientResult Retrieve(string fineTuningJobId, RequestOptions opti /// The ID of the fine-tuning job to get events for. /// Identifier for the last event from the previous pagination request. /// Number of events to retrieve. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> GetEventsAsync(string fineTuningJobId, string after = null, long? limit = null, CancellationToken cancellationToken = default) + public virtual async Task> GetEventsAsync(string fineTuningJobId, string after = null, long? limit = null) { Argument.AssertNotNullOrEmpty(fineTuningJobId, nameof(fineTuningJobId)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await GetEventsAsync(fineTuningJobId, after, limit, options).ConfigureAwait(false); + ClientResult result = await GetEventsAsync(fineTuningJobId, after, limit, null).ConfigureAwait(false); return ClientResult.FromValue(ListFineTuningJobEventsResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -338,15 +323,13 @@ public virtual async Task> GetEven /// The ID of the fine-tuning job to get events for. /// Identifier for the last event from the previous pagination request. /// Number of events to retrieve. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual ClientResult GetEvents(string fineTuningJobId, string after = null, long? limit = null, CancellationToken cancellationToken = default) + public virtual ClientResult GetEvents(string fineTuningJobId, string after = null, long? limit = null) { Argument.AssertNotNullOrEmpty(fineTuningJobId, nameof(fineTuningJobId)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = GetEvents(fineTuningJobId, after, limit, options); + ClientResult result = GetEvents(fineTuningJobId, after, limit, null); return ClientResult.FromValue(ListFineTuningJobEventsResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -360,7 +343,7 @@ public virtual ClientResult GetEvents(string fi /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -391,7 +374,7 @@ public virtual async Task GetEventsAsync(string fineTuningJobId, s /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -414,29 +397,25 @@ public virtual ClientResult GetEvents(string fineTuningJobId, string after, long /// Immediately cancel a fine-tune job. /// The ID of the fine-tuning job to cancel. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> CancelAsync(string fineTuningJobId, CancellationToken cancellationToken = default) + public virtual async Task> CancelAsync(string fineTuningJobId) { Argument.AssertNotNullOrEmpty(fineTuningJobId, nameof(fineTuningJobId)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await CancelAsync(fineTuningJobId, options).ConfigureAwait(false); + ClientResult result = await CancelAsync(fineTuningJobId, null).ConfigureAwait(false); return ClientResult.FromValue(FineTuningJob.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Immediately cancel a fine-tune job. /// The ID of the fine-tuning job to cancel. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual ClientResult Cancel(string fineTuningJobId, CancellationToken cancellationToken = default) + public virtual ClientResult Cancel(string fineTuningJobId) { Argument.AssertNotNullOrEmpty(fineTuningJobId, nameof(fineTuningJobId)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Cancel(fineTuningJobId, options); + ClientResult result = Cancel(fineTuningJobId, null); return ClientResult.FromValue(FineTuningJob.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -450,7 +429,7 @@ public virtual ClientResult Cancel(string fineTuningJobId, Cancel /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -479,7 +458,7 @@ public virtual async Task CancelAsync(string fineTuningJobId, Requ /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -611,17 +590,6 @@ internal PipelineMessage CreateCancelRequest(string fineTuningJobId, RequestOpti return message; } - private static RequestOptions DefaultRequestContext = new RequestOptions(); - internal static RequestOptions FromCancellationToken(CancellationToken cancellationToken = default) - { - if (!cancellationToken.CanBeCanceled) - { - return DefaultRequestContext; - } - - return new RequestOptions() { CancellationToken = cancellationToken }; - } - private static PipelineMessageClassifier _pipelineMessageClassifier200; private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); } diff --git a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Images.cs b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Images.cs index 20349e8fbb3..a6aed9ce3c2 100644 --- a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Images.cs +++ b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Images.cs @@ -5,7 +5,6 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; -using System.Threading; using System.Threading.Tasks; using OpenAI.Models; @@ -42,29 +41,25 @@ internal Images(ClientPipeline pipeline, ApiKeyCredential keyCredential, Uri end /// Creates an image given a prompt. /// The to use. - /// The cancellation token to use. /// is null. - public virtual async Task> CreateAsync(CreateImageRequest image, CancellationToken cancellationToken = default) + public virtual async Task> CreateAsync(CreateImageRequest image) { Argument.AssertNotNull(image, nameof(image)); using BinaryContent content = image.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await CreateAsync(content, options).ConfigureAwait(false); + ClientResult result = await CreateAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(ImagesResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Creates an image given a prompt. /// The to use. - /// The cancellation token to use. /// is null. - public virtual ClientResult Create(CreateImageRequest image, CancellationToken cancellationToken = default) + public virtual ClientResult Create(CreateImageRequest image) { Argument.AssertNotNull(image, nameof(image)); using BinaryContent content = image.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Create(content, options); + ClientResult result = Create(content, null); return ClientResult.FromValue(ImagesResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -78,7 +73,7 @@ public virtual ClientResult Create(CreateImageRequest image, Can /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -106,7 +101,7 @@ public virtual async Task CreateAsync(BinaryContent content, Reque /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -126,29 +121,25 @@ public virtual ClientResult Create(BinaryContent content, RequestOptions options /// Creates an edited or extended image given an original image and a prompt. /// The to use. - /// The cancellation token to use. /// is null. - public virtual async Task> CreateEditAsync(CreateImageEditRequest image, CancellationToken cancellationToken = default) + public virtual async Task> CreateEditAsync(CreateImageEditRequest image) { Argument.AssertNotNull(image, nameof(image)); using BinaryContent content = image.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await CreateEditAsync(content, options).ConfigureAwait(false); + ClientResult result = await CreateEditAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(ImagesResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Creates an edited or extended image given an original image and a prompt. /// The to use. - /// The cancellation token to use. /// is null. - public virtual ClientResult CreateEdit(CreateImageEditRequest image, CancellationToken cancellationToken = default) + public virtual ClientResult CreateEdit(CreateImageEditRequest image) { Argument.AssertNotNull(image, nameof(image)); using BinaryContent content = image.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = CreateEdit(content, options); + ClientResult result = CreateEdit(content, null); return ClientResult.FromValue(ImagesResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -162,7 +153,7 @@ public virtual ClientResult CreateEdit(CreateImageEditRequest im /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -190,7 +181,7 @@ public virtual async Task CreateEditAsync(BinaryContent content, R /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -210,29 +201,25 @@ public virtual ClientResult CreateEdit(BinaryContent content, RequestOptions opt /// Creates an edited or extended image given an original image and a prompt. /// The to use. - /// The cancellation token to use. /// is null. - public virtual async Task> CreateVariationAsync(CreateImageVariationRequest image, CancellationToken cancellationToken = default) + public virtual async Task> CreateVariationAsync(CreateImageVariationRequest image) { Argument.AssertNotNull(image, nameof(image)); using BinaryContent content = image.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await CreateVariationAsync(content, options).ConfigureAwait(false); + ClientResult result = await CreateVariationAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(ImagesResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Creates an edited or extended image given an original image and a prompt. /// The to use. - /// The cancellation token to use. /// is null. - public virtual ClientResult CreateVariation(CreateImageVariationRequest image, CancellationToken cancellationToken = default) + public virtual ClientResult CreateVariation(CreateImageVariationRequest image) { Argument.AssertNotNull(image, nameof(image)); using BinaryContent content = image.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = CreateVariation(content, options); + ClientResult result = CreateVariation(content, null); return ClientResult.FromValue(ImagesResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -246,7 +233,7 @@ public virtual ClientResult CreateVariation(CreateImageVariation /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -274,7 +261,7 @@ public virtual async Task CreateVariationAsync(BinaryContent conte /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -352,17 +339,6 @@ internal PipelineMessage CreateCreateVariationRequest(BinaryContent content, Req return message; } - private static RequestOptions DefaultRequestContext = new RequestOptions(); - internal static RequestOptions FromCancellationToken(CancellationToken cancellationToken = default) - { - if (!cancellationToken.CanBeCanceled) - { - return DefaultRequestContext; - } - - return new RequestOptions() { CancellationToken = cancellationToken }; - } - private static PipelineMessageClassifier _pipelineMessageClassifier200; private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); } diff --git a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/ModelsOps.cs b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/ModelsOps.cs index ec180df35c1..b647f0ddc3c 100644 --- a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/ModelsOps.cs +++ b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/ModelsOps.cs @@ -5,7 +5,6 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; -using System.Threading; using System.Threading.Tasks; using OpenAI.Models; @@ -44,11 +43,9 @@ internal ModelsOps(ClientPipeline pipeline, ApiKeyCredential keyCredential, Uri /// Lists the currently available models, and provides basic information about each one such as the /// owner and availability. /// - /// The cancellation token to use. - public virtual async Task> GetModelsAsync(CancellationToken cancellationToken = default) + public virtual async Task> GetModelsAsync() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await GetModelsAsync(options).ConfigureAwait(false); + ClientResult result = await GetModelsAsync(null).ConfigureAwait(false); return ClientResult.FromValue(ListModelsResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -56,11 +53,9 @@ public virtual async Task> GetModelsAsync(Cance /// Lists the currently available models, and provides basic information about each one such as the /// owner and availability. /// - /// The cancellation token to use. - public virtual ClientResult GetModels(CancellationToken cancellationToken = default) + public virtual ClientResult GetModels() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = GetModels(options); + ClientResult result = GetModels(null); return ClientResult.FromValue(ListModelsResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -75,7 +70,7 @@ public virtual ClientResult GetModels(CancellationToken canc /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -100,7 +95,7 @@ public virtual async Task GetModelsAsync(RequestOptions options) /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -119,15 +114,13 @@ public virtual ClientResult GetModels(RequestOptions options) /// permissioning. /// /// The ID of the model to use for this request. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> RetrieveAsync(string model, CancellationToken cancellationToken = default) + public virtual async Task> RetrieveAsync(string model) { Argument.AssertNotNullOrEmpty(model, nameof(model)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await RetrieveAsync(model, options).ConfigureAwait(false); + ClientResult result = await RetrieveAsync(model, null).ConfigureAwait(false); return ClientResult.FromValue(Model.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -136,15 +129,13 @@ public virtual async Task> RetrieveAsync(string model, Cance /// permissioning. /// /// The ID of the model to use for this request. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual ClientResult Retrieve(string model, CancellationToken cancellationToken = default) + public virtual ClientResult Retrieve(string model) { Argument.AssertNotNullOrEmpty(model, nameof(model)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Retrieve(model, options); + ClientResult result = Retrieve(model, null); return ClientResult.FromValue(Model.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -159,7 +150,7 @@ public virtual ClientResult Retrieve(string model, CancellationToken canc /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -189,7 +180,7 @@ public virtual async Task RetrieveAsync(string model, RequestOptio /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -210,29 +201,25 @@ public virtual ClientResult Retrieve(string model, RequestOptions options) /// Delete a fine-tuned model. You must have the Owner role in your organization to delete a model. /// The model to delete. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> DeleteAsync(string model, CancellationToken cancellationToken = default) + public virtual async Task> DeleteAsync(string model) { Argument.AssertNotNullOrEmpty(model, nameof(model)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await DeleteAsync(model, options).ConfigureAwait(false); + ClientResult result = await DeleteAsync(model, null).ConfigureAwait(false); return ClientResult.FromValue(DeleteModelResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Delete a fine-tuned model. You must have the Owner role in your organization to delete a model. /// The model to delete. - /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual ClientResult Delete(string model, CancellationToken cancellationToken = default) + public virtual ClientResult Delete(string model) { Argument.AssertNotNullOrEmpty(model, nameof(model)); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Delete(model, options); + ClientResult result = Delete(model, null); return ClientResult.FromValue(DeleteModelResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -246,7 +233,7 @@ public virtual ClientResult Delete(string model, Cancellati /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -275,7 +262,7 @@ public virtual async Task DeleteAsync(string model, RequestOptions /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -350,17 +337,6 @@ internal PipelineMessage CreateDeleteRequest(string model, RequestOptions option return message; } - private static RequestOptions DefaultRequestContext = new RequestOptions(); - internal static RequestOptions FromCancellationToken(CancellationToken cancellationToken = default) - { - if (!cancellationToken.CanBeCanceled) - { - return DefaultRequestContext; - } - - return new RequestOptions() { CancellationToken = cancellationToken }; - } - private static PipelineMessageClassifier _pipelineMessageClassifier200; private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); } diff --git a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Moderations.cs b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Moderations.cs index e7a2adb7741..09cc1e0918e 100644 --- a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Moderations.cs +++ b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/Generated/Moderations.cs @@ -5,7 +5,6 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; -using System.Threading; using System.Threading.Tasks; using OpenAI.Models; @@ -42,29 +41,25 @@ internal Moderations(ClientPipeline pipeline, ApiKeyCredential keyCredential, Ur /// Classifies if text violates OpenAI's Content Policy. /// The to use. - /// The cancellation token to use. /// is null. - public virtual async Task> CreateAsync(CreateModerationRequest content, CancellationToken cancellationToken = default) + public virtual async Task> CreateAsync(CreateModerationRequest content) { Argument.AssertNotNull(content, nameof(content)); using BinaryContent content0 = content.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await CreateAsync(content0, options).ConfigureAwait(false); + ClientResult result = await CreateAsync(content0, null).ConfigureAwait(false); return ClientResult.FromValue(CreateModerationResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Classifies if text violates OpenAI's Content Policy. /// The to use. - /// The cancellation token to use. /// is null. - public virtual ClientResult Create(CreateModerationRequest content, CancellationToken cancellationToken = default) + public virtual ClientResult Create(CreateModerationRequest content) { Argument.AssertNotNull(content, nameof(content)); using BinaryContent content0 = content.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = Create(content0, options); + ClientResult result = Create(content0, null); return ClientResult.FromValue(CreateModerationResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -78,7 +73,7 @@ public virtual ClientResult Create(CreateModerationReq /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -106,7 +101,7 @@ public virtual async Task CreateAsync(BinaryContent content, Reque /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -144,17 +139,6 @@ internal PipelineMessage CreateCreateRequest(BinaryContent content, RequestOptio return message; } - private static RequestOptions DefaultRequestContext = new RequestOptions(); - internal static RequestOptions FromCancellationToken(CancellationToken cancellationToken = default) - { - if (!cancellationToken.CanBeCanceled) - { - return DefaultRequestContext; - } - - return new RequestOptions() { CancellationToken = cancellationToken }; - } - private static PipelineMessageClassifier _pipelineMessageClassifier200; private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); } diff --git a/test/UnbrandedProjects/Unbranded-TypeSpec/src/Generated/UnbrandedTypeSpecClient.cs b/test/UnbrandedProjects/Unbranded-TypeSpec/src/Generated/UnbrandedTypeSpecClient.cs index d4836c2c78d..b969885fd53 100644 --- a/test/UnbrandedProjects/Unbranded-TypeSpec/src/Generated/UnbrandedTypeSpecClient.cs +++ b/test/UnbrandedProjects/Unbranded-TypeSpec/src/Generated/UnbrandedTypeSpecClient.cs @@ -5,7 +5,6 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; -using System.Threading; using System.Threading.Tasks; using UnbrandedTypeSpec.Models; @@ -108,18 +107,16 @@ public virtual ClientResult SayHi(string headParameter, string queryParameter, s /// The to use. /// The to use. /// The to use. - /// The cancellation token to use. /// , or is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> HelloAgainAsync(string p2, string p1, RoundTripModel action, CancellationToken cancellationToken = default) + public virtual async Task> HelloAgainAsync(string p2, string p1, RoundTripModel action) { Argument.AssertNotNullOrEmpty(p2, nameof(p2)); Argument.AssertNotNull(p1, nameof(p1)); Argument.AssertNotNull(action, nameof(action)); using BinaryContent content = action.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await HelloAgainAsync(p2, p1, content, options).ConfigureAwait(false); + ClientResult result = await HelloAgainAsync(p2, p1, content, null).ConfigureAwait(false); return ClientResult.FromValue(RoundTripModel.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -127,18 +124,16 @@ public virtual async Task> HelloAgainAsync(string p /// The to use. /// The to use. /// The to use. - /// The cancellation token to use. /// , or is null. /// is an empty string, and was expected to be non-empty. - public virtual ClientResult HelloAgain(string p2, string p1, RoundTripModel action, CancellationToken cancellationToken = default) + public virtual ClientResult HelloAgain(string p2, string p1, RoundTripModel action) { Argument.AssertNotNullOrEmpty(p2, nameof(p2)); Argument.AssertNotNull(p1, nameof(p1)); Argument.AssertNotNull(action, nameof(action)); using BinaryContent content = action.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = HelloAgain(p2, p1, content, options); + ClientResult result = HelloAgain(p2, p1, content, null); return ClientResult.FromValue(RoundTripModel.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -152,7 +147,7 @@ public virtual ClientResult HelloAgain(string p2, string p1, Rou /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -185,7 +180,7 @@ public virtual async Task HelloAgainAsync(string p2, string p1, Bi /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -265,20 +260,16 @@ public virtual ClientResult NoContentType(string p2, string p1, BinaryContent co } /// Return hi in demo2. - /// The cancellation token to use. - public virtual async Task> HelloDemo2Async(CancellationToken cancellationToken = default) + public virtual async Task> HelloDemo2Async() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await HelloDemo2Async(options).ConfigureAwait(false); + ClientResult result = await HelloDemo2Async(null).ConfigureAwait(false); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Return hi in demo2. - /// The cancellation token to use. - public virtual ClientResult HelloDemo2(CancellationToken cancellationToken = default) + public virtual ClientResult HelloDemo2() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = HelloDemo2(options); + ClientResult result = HelloDemo2(null); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -292,7 +283,7 @@ public virtual ClientResult HelloDemo2(CancellationToken cancellationToke /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -316,7 +307,7 @@ public virtual async Task HelloDemo2Async(RequestOptions options) /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -332,29 +323,25 @@ public virtual ClientResult HelloDemo2(RequestOptions options) /// Create with literal value. /// The to use. - /// The cancellation token to use. /// is null. - public virtual async Task> CreateLiteralAsync(Thing body, CancellationToken cancellationToken = default) + public virtual async Task> CreateLiteralAsync(Thing body) { Argument.AssertNotNull(body, nameof(body)); using BinaryContent content = body.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await CreateLiteralAsync(content, options).ConfigureAwait(false); + ClientResult result = await CreateLiteralAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Create with literal value. /// The to use. - /// The cancellation token to use. /// is null. - public virtual ClientResult CreateLiteral(Thing body, CancellationToken cancellationToken = default) + public virtual ClientResult CreateLiteral(Thing body) { Argument.AssertNotNull(body, nameof(body)); using BinaryContent content = body.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = CreateLiteral(content, options); + ClientResult result = CreateLiteral(content, null); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -368,7 +355,7 @@ public virtual ClientResult CreateLiteral(Thing body, CancellationToken c /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -396,7 +383,7 @@ public virtual async Task CreateLiteralAsync(BinaryContent content /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -415,20 +402,16 @@ public virtual ClientResult CreateLiteral(BinaryContent content, RequestOptions } /// Send literal parameters. - /// The cancellation token to use. - public virtual async Task> HelloLiteralAsync(CancellationToken cancellationToken = default) + public virtual async Task> HelloLiteralAsync() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await HelloLiteralAsync(options).ConfigureAwait(false); + ClientResult result = await HelloLiteralAsync(null).ConfigureAwait(false); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Send literal parameters. - /// The cancellation token to use. - public virtual ClientResult HelloLiteral(CancellationToken cancellationToken = default) + public virtual ClientResult HelloLiteral() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = HelloLiteral(options); + ClientResult result = HelloLiteral(null); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -442,7 +425,7 @@ public virtual ClientResult HelloLiteral(CancellationToken cancellationTo /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -466,7 +449,7 @@ public virtual async Task HelloLiteralAsync(RequestOptions options /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -482,21 +465,17 @@ public virtual ClientResult HelloLiteral(RequestOptions options) /// top level method. /// The to use. - /// The cancellation token to use. - public virtual async Task> TopActionAsync(DateTimeOffset action, CancellationToken cancellationToken = default) + public virtual async Task> TopActionAsync(DateTimeOffset action) { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await TopActionAsync(action, options).ConfigureAwait(false); + ClientResult result = await TopActionAsync(action, null).ConfigureAwait(false); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// top level method. /// The to use. - /// The cancellation token to use. - public virtual ClientResult TopAction(DateTimeOffset action, CancellationToken cancellationToken = default) + public virtual ClientResult TopAction(DateTimeOffset action) { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = TopAction(action, options); + ClientResult result = TopAction(action, null); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -510,7 +489,7 @@ public virtual ClientResult TopAction(DateTimeOffset action, Cancellation /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -535,7 +514,7 @@ public virtual async Task TopActionAsync(DateTimeOffset action, Re /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -636,29 +615,25 @@ public virtual ClientResult PatchAction(BinaryContent content, RequestOptions op /// body parameter without body decorator. /// A model with a few properties of literal types. - /// The cancellation token to use. /// is null. - public virtual async Task> AnonymousBodyAsync(Thing thing, CancellationToken cancellationToken = default) + public virtual async Task> AnonymousBodyAsync(Thing thing) { Argument.AssertNotNull(thing, nameof(thing)); using BinaryContent content = thing.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await AnonymousBodyAsync(content, options).ConfigureAwait(false); + ClientResult result = await AnonymousBodyAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// body parameter without body decorator. /// A model with a few properties of literal types. - /// The cancellation token to use. /// is null. - public virtual ClientResult AnonymousBody(Thing thing, CancellationToken cancellationToken = default) + public virtual ClientResult AnonymousBody(Thing thing) { Argument.AssertNotNull(thing, nameof(thing)); using BinaryContent content = thing.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = AnonymousBody(content, options); + ClientResult result = AnonymousBody(content, null); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -672,7 +647,7 @@ public virtual ClientResult AnonymousBody(Thing thing, CancellationToken /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -700,7 +675,7 @@ public virtual async Task AnonymousBodyAsync(BinaryContent content /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -720,29 +695,25 @@ public virtual ClientResult AnonymousBody(BinaryContent content, RequestOptions /// Model can have its friendly name. /// this is not a friendly model but with a friendly name. - /// The cancellation token to use. /// is null. - public virtual async Task> FriendlyModelAsync(Friend friend, CancellationToken cancellationToken = default) + public virtual async Task> FriendlyModelAsync(Friend friend) { Argument.AssertNotNull(friend, nameof(friend)); using BinaryContent content = friend.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await FriendlyModelAsync(content, options).ConfigureAwait(false); + ClientResult result = await FriendlyModelAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(Friend.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Model can have its friendly name. /// this is not a friendly model but with a friendly name. - /// The cancellation token to use. /// is null. - public virtual ClientResult FriendlyModel(Friend friend, CancellationToken cancellationToken = default) + public virtual ClientResult FriendlyModel(Friend friend) { Argument.AssertNotNull(friend, nameof(friend)); using BinaryContent content = friend.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = FriendlyModel(content, options); + ClientResult result = FriendlyModel(content, null); return ClientResult.FromValue(Friend.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -756,7 +727,7 @@ public virtual ClientResult FriendlyModel(Friend friend, CancellationTok /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -784,7 +755,7 @@ public virtual async Task FriendlyModelAsync(BinaryContent content /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -843,30 +814,26 @@ public virtual ClientResult AddTimeHeader(RequestOptions options = null) /// parameter has string format. /// The to use. /// The to use. - /// The cancellation token to use. /// is null. - public virtual async Task StringFormatAsync(Guid subscriptionId, ModelWithFormat body, CancellationToken cancellationToken = default) + public virtual async Task StringFormatAsync(Guid subscriptionId, ModelWithFormat body) { Argument.AssertNotNull(body, nameof(body)); using BinaryContent content = body.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await StringFormatAsync(subscriptionId, content, options).ConfigureAwait(false); + ClientResult result = await StringFormatAsync(subscriptionId, content, null).ConfigureAwait(false); return result; } /// parameter has string format. /// The to use. /// The to use. - /// The cancellation token to use. /// is null. - public virtual ClientResult StringFormat(Guid subscriptionId, ModelWithFormat body, CancellationToken cancellationToken = default) + public virtual ClientResult StringFormat(Guid subscriptionId, ModelWithFormat body) { Argument.AssertNotNull(body, nameof(body)); using BinaryContent content = body.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = StringFormat(subscriptionId, content, options); + ClientResult result = StringFormat(subscriptionId, content, null); return result; } @@ -880,7 +847,7 @@ public virtual ClientResult StringFormat(Guid subscriptionId, ModelWithFormat bo /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -909,7 +876,7 @@ public virtual async Task StringFormatAsync(Guid subscriptionId, B /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -930,29 +897,25 @@ public virtual ClientResult StringFormat(Guid subscriptionId, BinaryContent cont /// Model can have its projected name. /// this is a model with a projected name. - /// The cancellation token to use. /// is null. - public virtual async Task> ProjectedNameModelAsync(ProjectedModel projectedModel, CancellationToken cancellationToken = default) + public virtual async Task> ProjectedNameModelAsync(ProjectedModel projectedModel) { Argument.AssertNotNull(projectedModel, nameof(projectedModel)); using BinaryContent content = projectedModel.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await ProjectedNameModelAsync(content, options).ConfigureAwait(false); + ClientResult result = await ProjectedNameModelAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(ProjectedModel.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// Model can have its projected name. /// this is a model with a projected name. - /// The cancellation token to use. /// is null. - public virtual ClientResult ProjectedNameModel(ProjectedModel projectedModel, CancellationToken cancellationToken = default) + public virtual ClientResult ProjectedNameModel(ProjectedModel projectedModel) { Argument.AssertNotNull(projectedModel, nameof(projectedModel)); using BinaryContent content = projectedModel.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = ProjectedNameModel(content, options); + ClientResult result = ProjectedNameModel(content, null); return ClientResult.FromValue(ProjectedModel.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -966,7 +929,7 @@ public virtual ClientResult ProjectedNameModel(ProjectedModel pr /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -994,7 +957,7 @@ public virtual async Task ProjectedNameModelAsync(BinaryContent co /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -1013,20 +976,16 @@ public virtual ClientResult ProjectedNameModel(BinaryContent content, RequestOpt } /// return anonymous model. - /// The cancellation token to use. - public virtual async Task> ReturnsAnonymousModelAsync(CancellationToken cancellationToken = default) + public virtual async Task> ReturnsAnonymousModelAsync() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await ReturnsAnonymousModelAsync(options).ConfigureAwait(false); + ClientResult result = await ReturnsAnonymousModelAsync(null).ConfigureAwait(false); return ClientResult.FromValue(ReturnsAnonymousModelResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// return anonymous model. - /// The cancellation token to use. - public virtual ClientResult ReturnsAnonymousModel(CancellationToken cancellationToken = default) + public virtual ClientResult ReturnsAnonymousModel() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = ReturnsAnonymousModel(options); + ClientResult result = ReturnsAnonymousModel(null); return ClientResult.FromValue(ReturnsAnonymousModelResponse.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -1040,7 +999,7 @@ public virtual ClientResult ReturnsAnonymousModel /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -1064,7 +1023,7 @@ public virtual async Task ReturnsAnonymousModelAsync(RequestOption /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -1126,29 +1085,25 @@ public virtual ClientResult CreateUnknownValue(BinaryContent content, RequestOpt /// When set protocol false and convenient true, then the protocol method should be internal. /// The to use. - /// The cancellation token to use. /// is null. - public virtual async Task> InternalProtocolAsync(Thing body, CancellationToken cancellationToken = default) + public virtual async Task> InternalProtocolAsync(Thing body) { Argument.AssertNotNull(body, nameof(body)); using BinaryContent content = body.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await InternalProtocolAsync(content, options).ConfigureAwait(false); + ClientResult result = await InternalProtocolAsync(content, null).ConfigureAwait(false); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } /// When set protocol false and convenient true, then the protocol method should be internal. /// The to use. - /// The cancellation token to use. /// is null. - public virtual ClientResult InternalProtocol(Thing body, CancellationToken cancellationToken = default) + public virtual ClientResult InternalProtocol(Thing body) { Argument.AssertNotNull(body, nameof(body)); using BinaryContent content = body.ToBinaryContent(); - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = InternalProtocol(content, options); + ClientResult result = InternalProtocol(content, null); return ClientResult.FromValue(Thing.FromResponse(result.GetRawResponse()), result.GetRawResponse()); } @@ -1199,20 +1154,16 @@ internal virtual ClientResult InternalProtocol(BinaryContent content, RequestOpt } /// When set protocol false and convenient true, the convenient method should be generated even it has the same signature as protocol one. - /// The cancellation token to use. - public virtual async Task StillConvenientValueAsync(CancellationToken cancellationToken = default) + public virtual async Task StillConvenientValueAsync() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = await StillConvenientAsync(options).ConfigureAwait(false); + ClientResult result = await StillConvenientAsync(null).ConfigureAwait(false); return result; } /// When set protocol false and convenient true, the convenient method should be generated even it has the same signature as protocol one. - /// The cancellation token to use. - public virtual ClientResult StillConvenientValue(CancellationToken cancellationToken = default) + public virtual ClientResult StillConvenientValue() { - RequestOptions options = FromCancellationToken(cancellationToken); - ClientResult result = StillConvenient(options); + ClientResult result = StillConvenient(null); return result; } @@ -1685,17 +1636,6 @@ internal PipelineMessage CreateHeadAsBooleanRequest(string id, RequestOptions op return message; } - private static RequestOptions DefaultRequestContext = new RequestOptions(); - internal static RequestOptions FromCancellationToken(CancellationToken cancellationToken = default) - { - if (!cancellationToken.CanBeCanceled) - { - return DefaultRequestContext; - } - - return new RequestOptions() { CancellationToken = cancellationToken }; - } - private static PipelineMessageClassifier _pipelineMessageClassifier200; private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); private static PipelineMessageClassifier _pipelineMessageClassifier204;