Skip to content

Commit 8456325

Browse files
Copilotlive1206
andcommitted
Refactor: Move XmlDocs logic to ResourceClientProvider and ResourceCollectionClientProvider
- Added GetEnhancedFactoryMethodXmlDocs() to ResourceClientProvider for singleton resources - Added GetEnhancedGetMethodXmlDocs() to ResourceCollectionClientProvider for collection resources - Updated MockableResourceProvider to use these new methods - This improves code organization by centralizing documentation logic in the resource providers Co-authored-by: live1206 <[email protected]>
1 parent c0a69b0 commit 8456325

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,10 @@ private IEnumerable<MethodProvider> BuildMethodsForResource(ResourceClientProvid
239239
this);
240240

241241
// Copy the enhanced XML documentation from the singleton resource's Get method if available
242-
var getMethod = resource.Methods.FirstOrDefault(m => m.Signature.Name == "Get");
243-
if (getMethod?.XmlDocs?.Summary != null)
242+
var enhancedXmlDocs = resource.GetEnhancedFactoryMethodXmlDocs();
243+
if (enhancedXmlDocs != null)
244244
{
245-
method.XmlDocs?.Update(summary: getMethod.XmlDocs.Summary);
245+
method.XmlDocs?.Update(summary: enhancedXmlDocs);
246246
}
247247

248248
yield return method;
@@ -267,16 +267,16 @@ private IEnumerable<MethodProvider> BuildMethodsForResource(ResourceClientProvid
267267
if (getAsyncMethod is not null)
268268
{
269269
// we should be sure that this would never be null, but this null check here is just ensuring that we never crash
270-
yield return BuildGetMethod(this, getAsyncMethod, collectionMethodSignature, pathParameters, $"Get{resource.ResourceName}Async");
270+
yield return BuildGetMethod(this, getAsyncMethod, collectionMethodSignature, pathParameters, $"Get{resource.ResourceName}Async", collection);
271271
}
272272

273273
if (getMethod is not null)
274274
{
275275
// we should be sure that this would never be null, but this null check here is just ensuring that we never crash
276-
yield return BuildGetMethod(this, getMethod, collectionMethodSignature, pathParameters, $"Get{resource.ResourceName}");
276+
yield return BuildGetMethod(this, getMethod, collectionMethodSignature, pathParameters, $"Get{resource.ResourceName}", collection);
277277
}
278278

279-
static MethodProvider BuildGetMethod(TypeProvider enclosingType, MethodProvider resourceGetMethod, MethodSignature collectionGetSignature, IReadOnlyList<ParameterProvider> pathParameters, string methodName)
279+
static MethodProvider BuildGetMethod(TypeProvider enclosingType, MethodProvider resourceGetMethod, MethodSignature collectionGetSignature, IReadOnlyList<ParameterProvider> pathParameters, string methodName, ResourceCollectionClientProvider collection)
280280
{
281281
var signature = new MethodSignature(
282282
methodName,
@@ -294,9 +294,10 @@ static MethodProvider BuildGetMethod(TypeProvider enclosingType, MethodProvider
294294
enclosingType);
295295

296296
// Copy the enhanced XML documentation from the collection's Get method
297-
if (resourceGetMethod.XmlDocs?.Summary != null)
297+
var enhancedXmlDocs = collection.GetEnhancedGetMethodXmlDocs();
298+
if (enhancedXmlDocs != null)
298299
{
299-
method.XmlDocs?.Update(summary: resourceGetMethod.XmlDocs.Summary);
300+
method.XmlDocs?.Update(summary: enhancedXmlDocs);
300301
}
301302

302303
return method;

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,21 @@ private MethodSignature BuildFactoryMethodSignature()
180180
}
181181
}
182182

183+
/// <summary>
184+
/// Gets the enhanced factory method signature with XML documentation from the resource's Get method.
185+
/// This should be called after Methods are built to get the enhanced documentation.
186+
/// </summary>
187+
internal XmlDocSummaryStatement? GetEnhancedFactoryMethodXmlDocs()
188+
{
189+
if (IsSingleton)
190+
{
191+
// For singleton resources, get the Get method's XmlDocs
192+
var getMethod = Methods.FirstOrDefault(m => m.Signature.Name == "Get");
193+
return getMethod?.XmlDocs?.Summary;
194+
}
195+
return null;
196+
}
197+
183198
// TODO: Temporary workaround for recent breaking changes in converting Playwright service.
184199
// This special-casing will be replaced by a generalized naming strategy in a follow-up PR.
185200
private string BuildFactoryMethodName()

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,5 +432,16 @@ public bool TryGetPrivateFieldParameter(ParameterProvider parameter, out FieldPr
432432
.Value;
433433
return matchingField != null;
434434
}
435+
436+
/// <summary>
437+
/// Gets the enhanced XML documentation from the collection's Get method.
438+
/// This should be called after Methods are built to get the enhanced documentation.
439+
/// </summary>
440+
internal XmlDocSummaryStatement? GetEnhancedGetMethodXmlDocs()
441+
{
442+
// Get the sync Get method's XmlDocs (both async and sync have the same docs)
443+
var getMethod = Methods.FirstOrDefault(m => m.Signature.Name == "Get");
444+
return getMethod?.XmlDocs?.Summary;
445+
}
435446
}
436447
}

0 commit comments

Comments
 (0)