Skip to content
This repository was archived by the owner on Jun 16, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a8eeca4
remove cancellationtoken on nonazure convenience methods
ArcturusZhang Apr 3, 2024
1eaea61
update code to remove some unused methods
ArcturusZhang Apr 3, 2024
fc4d4b8
update the document on protocol methods
ArcturusZhang Apr 3, 2024
fdce61a
fix regenerate issue
ArcturusZhang Apr 3, 2024
a633b43
Merge branch 'feature/v3' into enable-new-cancellationtoken-pattern
ArcturusZhang Apr 3, 2024
10187fe
Merge branch 'feature/v3' into enable-new-cancellationtoken-pattern
ArcturusZhang Apr 7, 2024
3048edd
fix the link and regen
ArcturusZhang Apr 7, 2024
3f4cea7
Merge branch 'feature/v3' into enable-new-cancellationtoken-pattern
ArcturusZhang Apr 9, 2024
8747988
regen
ArcturusZhang Apr 9, 2024
d1b8e19
Merge branch 'feature/v3' into enable-new-cancellationtoken-pattern
ArcturusZhang Apr 9, 2024
c17da1a
Merge remote-tracking branch 'origin/feature/v3' into enable-new-canc…
ArcturusZhang Apr 10, 2024
9a272d6
Merge remote-tracking branch 'origin/feature/v3' into enable-new-canc…
ArcturusZhang Apr 11, 2024
0436099
make the code change
ArcturusZhang Apr 12, 2024
5776e75
regen
ArcturusZhang Apr 12, 2024
52b2ddd
fix the requiredness of requestcontext parameter
ArcturusZhang Apr 12, 2024
ee69dd1
regen, but it has some issues, need to investigate why it becomes thi…
ArcturusZhang Apr 12, 2024
7a6253e
fix the issue
ArcturusZhang Apr 12, 2024
18e048e
add a comment to explain the changes
ArcturusZhang Apr 12, 2024
5db5c6e
Merge remote-tracking branch 'origin/feature/v3' into enable-new-canc…
ArcturusZhang Apr 12, 2024
08afee6
Merge remote-tracking branch 'origin/feature/v3' into enable-new-canc…
ArcturusZhang Apr 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/AutoRest.CSharp/LowLevel/Generation/DpgClientWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,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();
}
Expand Down Expand Up @@ -724,13 +725,16 @@ private void WriteCancellationTokenToRequestContextMethod()

private static FormattableString BuildProtocolMethodSummary(MethodSignature methodSignature, LowLevelClientMethod clientMethod, bool async)
{
List<FormattableString> lines = new()
var linkForProtocol = Configuration.IsBranded
? "https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/ProtocolMethods.md"
: "https://aka.ms/azsdk/net/protocol-methods";
List <FormattableString> lines = new()
{
$"[Protocol Method] {methodSignature.SummaryText}",
$"<list type=\"bullet\">",
$"<item>",
$"<description>",
$"This <see href=\"https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/ProtocolMethods.md\">protocol method</see> allows explicit creation of the request and processing of the response for advanced scenarios.",
$"This <see href={linkForProtocol:L}>protocol method</see> allows explicit creation of the request and processing of the response for advanced scenarios.",
$"</description>",
$"</item>"
};
Expand Down
8 changes: 6 additions & 2 deletions src/AutoRest.CSharp/LowLevel/Output/ConvenienceMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal record ConvenienceMethod(MethodSignature Signature, IReadOnlyList<Proto

private record RequestContentParameterInfo(CodeWriterDeclaration ContentVariable, FormattableString ContentValue);

private (IReadOnlyList<FormattableString> ParameterValues, RequestContentParameterInfo? ContentInfo, CodeWriterDeclaration? SpreadVariable) PrepareConvenienceMethodParameters(CodeWriterDeclaration contextVariable)
private (IReadOnlyList<FormattableString> ParameterValues, RequestContentParameterInfo? ContentInfo, CodeWriterDeclaration? SpreadVariable) PrepareConvenienceMethodParameters(CodeWriterDeclaration contextVariable)
{
CodeWriterDeclaration? spreadVariable = null;
var parameters = new List<FormattableString>();
Expand Down Expand Up @@ -108,7 +108,11 @@ private Action<CodeWriter> EnsureConvenienceBodyConverter(CodeWriterDeclaration?
// RequestContext context = FromCancellationToken(cancellationToken);
private static void WriteCancellationTokenToRequestContext(CodeWriter writer, CodeWriterDeclaration contextVariable)
{
writer.Line($"{Configuration.ApiTypes.RequestContextType} {contextVariable:D} = FromCancellationToken({KnownParameters.CancellationTokenParameter.Name});");
// non-branded convenience methods do not have the cancellationToken parameter any more therefore they no longer need this conversion
if (Configuration.IsBranded)
{
writer.Line($"{Configuration.ApiTypes.RequestContextType} {contextVariable:D} = FromCancellationToken({KnownParameters.CancellationTokenParameter.Name});");
}
}

private static void WriteBodyToRequestContent(CodeWriter writer, CodeWriterDeclaration contentVariable, FormattableString requestContentValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
20 changes: 15 additions & 5 deletions src/AutoRest.CSharp/LowLevel/Output/OperationMethodChainBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,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);
}

Expand Down Expand Up @@ -589,10 +589,20 @@ public void AddRequestConditionHeaders(RequestConditionHeaders conditionHeaderFl

public void AddRequestContext()
{
_orderedParameters.Add(new ParameterChain(
KnownParameters.CancellationTokenParameter,
ShouldRequestContextOptional() ? KnownParameters.RequestContext : KnownParameters.RequestContextRequired,
KnownParameters.RequestContext));
if (Configuration.IsBranded)
{
_orderedParameters.Add(new ParameterChain(
KnownParameters.CancellationTokenParameter,
ShouldRequestContextOptional() ? KnownParameters.RequestContext : KnownParameters.RequestContextRequired,
KnownParameters.RequestContext));
}
else
{
_orderedParameters.Add(new ParameterChain(
null,
KnownParameters.RequestContext,
KnownParameters.RequestContext));
}
}

private void AddContentTypeRequestParameter(InputParameter operationParameter, IReadOnlyList<string> requestMediaTypes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading