Skip to content

Commit 1529ed3

Browse files
authored
For a non-single resource, if there is no update method, use create as update method (Azure#53456)
* For a non-single resource, if there is no update method, we should use create as update method * refine
1 parent d642949 commit 1529ed3

File tree

6 files changed

+1868
-2340
lines changed

6 files changed

+1868
-2340
lines changed

eng/packages/http-client-csharp-mgmt/generator/Azure.Generator.Management/src/Providers/ResourceClientProvider.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,6 @@ protected override MethodProvider[] BuildMethods()
414414
var methodKind = resourceMethod.Kind;
415415
var method = resourceMethod.InputMethod;
416416
var inputClient = resourceMethod.InputClient;
417-
// exclude the List operations for resource and Create operations for non-singleton resources (they will be in ResourceCollection)
418-
if (methodKind == ResourceOperationKind.List || (!IsSingleton && methodKind == ResourceOperationKind.Create))
419-
{
420-
continue;
421-
}
422417

423418
var isFakeLro = ResourceHelpers.ShouldMakeLro(methodKind);
424419

eng/packages/http-client-csharp-mgmt/generator/Azure.Generator.Management/src/Utilities/ResourceMetadataExtensions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public static ResourceMethodCategory CategorizeMethods(this ResourceMetadata res
4848
var methodsInResource = new List<ResourceMethod>();
4949
var methodsInCollection = new List<ResourceMethod>();
5050
var methodsInExtension = new List<ResourceMethod>();
51+
bool hasUpdateMethod = false;
52+
ResourceMethod? createMethod = null;
53+
5154
foreach (var method in resourceMetadata.Methods)
5255
{
5356
var isSingleton = resourceMetadata.SingletonResourceName is not null;
@@ -63,13 +66,17 @@ public static ResourceMethodCategory CategorizeMethods(this ResourceMetadata res
6366
{
6467
methodsInCollection.Add(method);
6568
}
69+
createMethod = method;
6670
break;
6771
case ResourceOperationKind.Get:
6872
// both resource and collection should have get method
6973
methodsInResource.Add(method);
7074
methodsInCollection.Add(method);
7175
break;
7276
case ResourceOperationKind.Update:
77+
hasUpdateMethod = true;
78+
methodsInResource.Add(method);
79+
break;
7380
case ResourceOperationKind.Delete:
7481
// only resource has get
7582
methodsInResource.Add(method);
@@ -114,6 +121,12 @@ public static ResourceMethodCategory CategorizeMethods(this ResourceMetadata res
114121
}
115122
}
116123

124+
// For non-singleton resource, if there is no update method, we will add the create method as update to the resource methods.
125+
if (resourceMetadata.SingletonResourceName is null && !hasUpdateMethod && createMethod is not null)
126+
{
127+
methodsInResource.Add(createMethod);
128+
}
129+
117130
return new(methodsInResource, methodsInCollection, methodsInExtension);
118131
}
119132
}

eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/foo.tsp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ interface Foos {
5151

5252
delete is ArmResourceDeleteWithoutOkAsync<Foo>;
5353

54-
update is ArmCustomPatchAsync<Foo, Foo>;
55-
5654
list is ArmResourceListByParent<Foo>;
5755

5856
listBySubscription is ArmListBySubscription<Foo>;

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

Lines changed: 20 additions & 42 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/RestOperations/FoosRestOperations.cs

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

0 commit comments

Comments
 (0)