Skip to content

Commit e773d19

Browse files
Copilotlive1206
andauthored
Rename Etag to ETag in management plane generator (Azure#53393)
* Initial plan * Add Etag to ETag renaming in NameVisitor Co-authored-by: live1206 <[email protected]> * Refactor Etag renaming to use dictionary for extensibility Co-authored-by: live1206 <[email protected]> * Move _propertyNameRenamingMap closer to its usage Co-authored-by: live1206 <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: live1206 <[email protected]>
1 parent 1529ed3 commit e773d19

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ private void UpdateSerialization(ModelProvider type, string newName, string orig
116116
DoPreVisitPropertyForResourceTypeName(property, propertyProvider);
117117
DoPreVisitPropertyForUrlPropertyName(property, propertyProvider);
118118
DoPreVisitPropertyForTimePropertyName(property, propertyProvider);
119+
DoPreVisitPropertyNameRenaming(property, propertyProvider);
119120
return base.PreVisitProperty(property, propertyProvider);
120121
}
121122

@@ -196,6 +197,20 @@ private void DoPreVisitPropertyForTimePropertyName(InputProperty property, Prope
196197
}
197198
}
198199

200+
// Dictionary to hold property name renaming mappings
201+
private static readonly Dictionary<string, string> _propertyNameRenamingMap = new()
202+
{
203+
{"Etag", "ETag"}
204+
};
205+
206+
private void DoPreVisitPropertyNameRenaming(InputProperty property, PropertyProvider? propertyProvider)
207+
{
208+
if (propertyProvider != null && _propertyNameRenamingMap.TryGetValue(propertyProvider.Name, out var newPropertyName))
209+
{
210+
propertyProvider.Update(name: newPropertyName);
211+
}
212+
}
213+
199214
protected override MethodProvider? VisitMethod(MethodProvider method)
200215
{
201216
var parameterUpdated = false;

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,29 @@ public void TestPrependResourceProviderNameForEnum()
116116
var updatedSkuModelName = $"{resourceProviderName}{enumName}";
117117
Assert.AreEqual(type?.Name, updatedSkuModelName);
118118
}
119+
120+
[Test]
121+
public void TestTransformEtagToETag()
122+
{
123+
const string testModelName = "TestModel";
124+
const string testPropertyName = "Etag";
125+
var modelProperty = InputFactory.Property(testPropertyName, InputPrimitiveType.String, serializedName: "etag", isRequired: true);
126+
var model = InputFactory.Model(testModelName, properties: [modelProperty]);
127+
var responseType = InputFactory.OperationResponse(statusCodes: [200], bodytype: model);
128+
var testNameParameter = InputFactory.MethodParameter("testName", InputPrimitiveType.String, location: InputRequestLocation.Path);
129+
var operation = InputFactory.Operation(name: "get", responses: [responseType], parameters: [testNameParameter], path: "/providers/a/test/{testName}", decorators: []);
130+
131+
var client = InputFactory.Client(
132+
TestClientName,
133+
methods: [InputFactory.BasicServiceMethod("Get", operation, parameters: [testNameParameter])],
134+
crossLanguageDefinitionId: $"Test.{TestClientName}",
135+
decorators: []);
136+
137+
var plugin = ManagementMockHelpers.LoadMockPlugin(inputModels: () => [model], clients: () => [client]);
138+
139+
// PreVisitModel is called during the model creation
140+
var type = plugin.Object.TypeFactory.CreateModel(model);
141+
Assert.That(type?.Properties[0].Name, Is.EqualTo("ETag"));
142+
}
119143
}
120144
}

0 commit comments

Comments
 (0)