Skip to content

Commit 7e5aec5

Browse files
authored
fix Resource Collection documentation. (#53832)
1 parent 23e50b2 commit 7e5aec5

File tree

12 files changed

+58
-60
lines changed

12 files changed

+58
-60
lines changed

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

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Azure.Generator.Management.Utilities;
1010
using Azure.ResourceManager;
1111
using Azure.ResourceManager.Resources;
12+
using Azure.ResourceManager.ManagementGroups;
1213
using Humanizer;
1314
using Microsoft.TypeSpec.Generator.Input;
1415
using Microsoft.TypeSpec.Generator.Input.Extensions;
@@ -135,8 +136,11 @@ private static void InitializeMethods(
135136

136137
protected override string BuildName() => $"{ResourceName}Collection";
137138

138-
// TODO: Add support for getting parent resource from a resource collection
139-
protected override FormattableString BuildDescription() => $"A class representing a collection of {_resource.Type:C} and their operations.\nEach {_resource.Type:C} in the collection will belong to the same instance of a parent resource (TODO: add parent resource information).\nTo get a {Type:C} instance call the Get{ResourceName.Pluralize()} method from an instance of the parent resource.";
139+
protected override FormattableString BuildDescription()
140+
{
141+
var parentResourceType = GetParentResourceType(_resourceMetadata, _resource);
142+
return $"A class representing a collection of {_resource.Type:C} and their operations.\nEach {_resource.Type:C} in the collection will belong to the same instance of {parentResourceType:C}.\nTo get a {Type:C} instance call the Get{ResourceName.Pluralize()} method from an instance of {parentResourceType:C}.";
143+
}
140144

141145
protected override string BuildRelativeFilePath() => Path.Combine("src", "Generated", $"{Name}.cs");
142146

@@ -252,7 +256,11 @@ private ConstructorProvider BuildResourceIdentifierConstructor()
252256
bodyStatements.Add(clientInfo.RestClientField.Assign(New.Instance(clientInfo.RestClientProvider.Type, clientInfo.DiagnosticsField, thisCollection.Pipeline(), thisCollection.Endpoint(), effectiveApiVersion)).Terminate());
253257
}
254258

255-
bodyStatements.Add(Static(Type).As<ArmCollection>().ValidateResourceId(idParameter).Terminate());
259+
// Do not call ValidateResourceId for Extension resources
260+
if (_resourceMetadata.ResourceScope != ResourceScope.Extension)
261+
{
262+
bodyStatements.Add(Static(Type).As<ArmCollection>().ValidateResourceId(idParameter).Terminate());
263+
}
256264

257265
return new ConstructorProvider(signature, bodyStatements, this);
258266
}
@@ -274,22 +282,35 @@ private static CSharpType GetParentResourceType(ResourceMetadata resourceMetadat
274282
return typeof(SubscriptionResource);
275283
case ResourceScope.Tenant:
276284
return typeof(TenantResource);
285+
case ResourceScope.Extension:
286+
return typeof(ArmResource);
287+
case ResourceScope.ManagementGroup:
288+
return typeof(ManagementGroupResource);
277289
default:
278290
// TODO -- this is incorrect, but we put it here as a placeholder.
279291
return resource.Type;
280292
}
281293
}
282294

283295
protected override MethodProvider[] BuildMethods()
284-
=> [
285-
ResourceMethodSnippets.BuildValidateResourceIdMethod(this, Static(GetParentResourceType(_resourceMetadata, _resource)).As<ArmResource>().ResourceType()),
286-
.. BuildCreateOrUpdateMethods(),
287-
.. BuildGetMethods(),
288-
.. BuildGetAllMethods(),
289-
.. BuildExistsMethods(),
290-
.. BuildGetIfExistsMethods(),
291-
.. BuildEnumeratorMethods()
292-
];
296+
{
297+
var methods = new List<MethodProvider>();
298+
299+
// Do not build ValidateResourceIdMethod for Extension resources
300+
if (_resourceMetadata.ResourceScope != ResourceScope.Extension)
301+
{
302+
methods.Add(ResourceMethodSnippets.BuildValidateResourceIdMethod(this, Static(GetParentResourceType(_resourceMetadata, _resource)).As<ArmResource>().ResourceType()));
303+
}
304+
305+
methods.AddRange(BuildCreateOrUpdateMethods());
306+
methods.AddRange(BuildGetMethods());
307+
methods.AddRange(BuildGetAllMethods());
308+
methods.AddRange(BuildExistsMethods());
309+
methods.AddRange(BuildGetIfExistsMethods());
310+
methods.AddRange(BuildEnumeratorMethods());
311+
312+
return [.. methods];
313+
}
293314

294315
private MethodProvider[] BuildGetAllMethods()
295316
{

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

Lines changed: 2 additions & 2 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/BarQuotaResourceCollection.cs

Lines changed: 2 additions & 2 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/BazCollection.cs

Lines changed: 2 additions & 2 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/EndpointResourceCollection.cs

Lines changed: 2 additions & 14 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/FooCollection.cs

Lines changed: 2 additions & 2 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/GroupQuotaSubscriptionRequestStatusCollection.cs

Lines changed: 5 additions & 4 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/JobResourceCollection.cs

Lines changed: 2 additions & 2 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/JooCollection.cs

Lines changed: 2 additions & 2 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/PlaywrightQuotaCollection.cs

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

0 commit comments

Comments
 (0)