Skip to content

Commit 87a6d64

Browse files
ArcturusZhangCopilotlive1206
authored
bump dependencies for azure mgmt generator (#51938)
* first commit to refactor the existing visitor * replace the diagnostic scope * clean up * Update eng/packages/http-client-csharp-mgmt/generator/Azure.Generator.Management/src/Utilities/ResourceHelpers.cs Co-authored-by: Copilot <[email protected]> * bump version * fix the issues in getnextresponse * fix the implicit operator replacement * format the code * pin the version of nuget packages to avoid future issues * fix test compilation issue * regen * cleanup * cleanup * cleanup * minor * regen --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: Wei Hu <[email protected]>
1 parent df728e7 commit 87a6d64

File tree

62 files changed

+2550
-5468
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2550
-5468
lines changed

eng/Packages.Data.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,6 @@
458458
<PropertyGroup>
459459
<TestProxyVersion>1.0.0-dev.20250805.1</TestProxyVersion>
460460
<UnbrandedGeneratorVersion>1.0.0-alpha.20250813.2</UnbrandedGeneratorVersion>
461-
<AzureGeneratorVersion>1.0.0-alpha.20250729.4</AzureGeneratorVersion>
461+
<AzureGeneratorVersion>1.0.0-alpha.20250812.2</AzureGeneratorVersion>
462462
</PropertyGroup>
463463
</Project>

eng/packages/http-client-csharp-mgmt/generator/Azure.Generator.Management/src/Azure.Generator.Management.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212
<PackageReference Include="Humanizer.Core" />
1313
</ItemGroup>
1414

15-
<!-- temporarily. remove once Azure.Generator version update is done -->
16-
<ItemGroup>
17-
<PackageReference Update="Microsoft.TypeSpec.Generator.ClientModel" VersionOverride="1.0.0-alpha.20250731.2" />
18-
<PackageReference Update="Microsoft.TypeSpec.Generator.Input" VersionOverride="1.0.0-alpha.20250731.2" />
19-
</ItemGroup>
20-
2115
<Target Name="CheckEmitterBuild" BeforeTargets="Build">
2216
<!-- Check if the folder does not exist -->
2317
<Error Condition="!Exists('..\..\..\node_modules\@typespec\http-client-csharp')" Text="Emitter has not been built please run `npm ci` followed by `npm run build` from ./eng/packages/http-client-csharp folder." />

eng/packages/http-client-csharp-mgmt/generator/Azure.Generator.Management/src/Visitors/PaginationVisitor.cs

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.TypeSpec.Generator.Providers;
77
using Microsoft.TypeSpec.Generator.Statements;
88
using System;
9+
using System.Collections.Generic;
910
using System.Linq;
1011
using static Microsoft.TypeSpec.Generator.Snippets.Snippet;
1112

@@ -37,25 +38,54 @@ internal class PaginationVisitor : ScmLibraryVisitor
3738
}
3839

3940
private static bool IsAsPagesMethod(MethodProvider method) => method.Signature.Name.Equals("AsPages");
40-
private static bool IsGetNextResponseMethod(MethodProvider method) => method.Signature.Name.Equals("GetNextResponse");
41+
private static bool IsGetNextResponseMethod(MethodProvider method)
42+
=> method.Signature.Name.Equals("GetNextResponseAsync") || method.Signature.Name.Equals("GetNextResponse");
4143

4244
private void DoVisitAsPagesMethodStatements(MethodBodyStatements statements, MethodProvider method)
4345
{
44-
var doWhileStatement = statements.OfType<DoWhileStatement>().FirstOrDefault();
45-
if (doWhileStatement is not null)
46+
var whileStatement = statements.OfType<WhileStatement>().FirstOrDefault();
47+
if (whileStatement is not null)
4648
{
4749
// we manually go over the body statements because currently the framework does not do this.
4850
// TODO -- we do not have to do this once https://github.com/microsoft/typespec/issues/8177 is fixed.
49-
foreach (var statement in doWhileStatement.Body)
51+
foreach (var statement in whileStatement.Body)
5052
{
51-
if (statement is ExpressionStatement { Expression: AssignmentExpression assignment } expressionStatement)
53+
if (statement is YieldReturnStatement
54+
{
55+
Value: InvokeMethodExpression
56+
{
57+
MethodName: "FromValues",
58+
Arguments: [CastExpression castExpression, ..]
59+
} invokeMethodExpression
60+
} &&
61+
castExpression.Inner is MemberExpression
62+
{
63+
Inner: CastExpression innerCastExpression,
64+
MemberName: var memberName
65+
} &&
66+
IsResponseToModelCastExpression(innerCastExpression))
67+
{
68+
// convert the implicit cast expression to a method call
69+
var updatedExpression = ConvertCastToMethodCall(innerCastExpression)
70+
.Property(memberName) // wrap back by a MemberExpression
71+
.CastTo(castExpression.Type); // wrap back by the outer CastExpression
72+
// use the above updated expression as the first argument of this method call inside the yield return
73+
IReadOnlyList<ValueExpression> newArguments = [updatedExpression, .. invokeMethodExpression.Arguments.Skip(1)];
74+
invokeMethodExpression.Update(arguments: newArguments);
75+
}
76+
else if (statement is ExpressionStatement
5277
{
53-
var updatedExpression = DoVisitAssignmentExpressionForAsPagesMethod(assignment, method);
54-
if (updatedExpression is not null)
78+
Expression: AssignmentExpression
5579
{
56-
// update the expression in the statement.
57-
expressionStatement.Update(updatedExpression);
80+
Variable: var variable,
81+
Value: MemberExpression { Inner: CastExpression castExpression1, MemberName: var memberName1 }
5882
}
83+
} expressionStatement)
84+
{
85+
var updatedExpression = variable.Assign(
86+
ConvertCastToMethodCall(castExpression1)
87+
.Property(memberName1)); // wrap back by a MemberExpression
88+
expressionStatement.Update(updatedExpression);
5989
}
6090
}
6191
}
@@ -89,23 +119,17 @@ private void DoVisitAsPagesMethodStatements(MethodBodyStatements statements, Met
89119
{
90120
if (expression.Value is CastExpression castExpression && IsResponseToModelCastExpression(castExpression))
91121
{
92-
var value = Static(castExpression.Type!).Invoke(SerializationVisitor.FromResponseMethodName, [castExpression.Inner!]);
122+
var value = ConvertCastToMethodCall(castExpression);
93123
var variable = expression.Variable;
94124
return variable.Assign(value);
95125
}
96126
// do nothing if nothing is changed.
97127
return null;
128+
}
98129

99-
static bool IsResponseToModelCastExpression(CastExpression castExpression)
100-
{
101-
if (castExpression.Inner is VariableExpression variableExpression &&
102-
variableExpression.Type is { IsFrameworkType: true, FrameworkType: { } frameworkType } &&
103-
frameworkType == typeof(Response))
104-
{
105-
return true;
106-
}
107-
return false;
108-
}
130+
private static ValueExpression ConvertCastToMethodCall(CastExpression castExpression)
131+
{
132+
return Static(castExpression.Type!).Invoke(SerializationVisitor.FromResponseMethodName, [castExpression.Inner!]);
109133
}
110134

111135
private ValueExpression? DoVisitAssignmentExpressionForGetNextResponseMethod(AssignmentExpression expression, MethodProvider method)
@@ -131,4 +155,9 @@ static bool IsResponseToModelCastExpression(CastExpression castExpression)
131155
// do nothing if nothing is changed.
132156
return null;
133157
}
158+
159+
private static bool IsResponseToModelCastExpression(CastExpression castExpression)
160+
=> castExpression.Inner is VariableExpression variableExpression
161+
&& variableExpression.Type is { IsFrameworkType: true, FrameworkType: { } frameworkType }
162+
&& frameworkType == typeof(Response);
134163
}

eng/packages/http-client-csharp-mgmt/generator/Azure.Generator.Management/test/Azure.Generator.Mgmt.Tests.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,4 @@
3232
<ProjectReference Include="Common\Azure.Generator.Management.Tests.Common.csproj" />
3333
</ItemGroup>
3434

35-
<!-- temporarily. remove once Azure.Generator version update is done -->
36-
<ItemGroup>
37-
<PackageReference Update="Microsoft.TypeSpec.Generator.ClientModel" VersionOverride="1.0.0-alpha.20250731.2" />
38-
<PackageReference Update="Microsoft.TypeSpec.Generator.Input" VersionOverride="1.0.0-alpha.20250731.2" />
39-
</ItemGroup>
40-
4135
</Project>

eng/packages/http-client-csharp-mgmt/generator/Azure.Generator.Management/test/Common/Azure.Generator.Management.Tests.Common.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,4 @@
1818
<ProjectReference Include="..\..\src\Azure.Generator.Management.csproj" />
1919
</ItemGroup>
2020

21-
<!-- temporarily. remove once Azure.Generator version update is done -->
22-
<ItemGroup>
23-
<PackageReference Update="Microsoft.TypeSpec.Generator.ClientModel" VersionOverride="1.0.0-alpha.20250731.2" />
24-
<PackageReference Update="Microsoft.TypeSpec.Generator.Input" VersionOverride="1.0.0-alpha.20250731.2" />
25-
</ItemGroup>
26-
2721
</Project>

eng/packages/http-client-csharp-mgmt/generator/Azure.Generator.Management/test/Common/InputFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ public static InputModelProperty Property(
221221
access: null,
222222
isDiscriminator,
223223
serializedName ?? wireName ?? name.ToVariableName(),
224+
false,
224225
new(json: new(wireName ?? name)));
225226
}
226227

eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/BarsGetAsyncCollectionResult.cs

Lines changed: 0 additions & 91 deletions
This file was deleted.

eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/BarsGetAsyncCollectionResultOfT.cs

Lines changed: 9 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/BarsGetCollectionResult.cs

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)