Skip to content

Commit 91b92c2

Browse files
Copilotlive1206
andauthored
Add enhanced XML documentation to MPG generator operation methods (#53473)
* Initial plan * Add enhanced XML documentation to MPG generator methods Co-authored-by: live1206 <[email protected]> * Document XML encoding limitation in code comments Co-authored-by: live1206 <[email protected]> * Use XmlDocStatement to build structured XML documentation Instead of using FormattableString with raw XML tags that get HTML-encoded, now using XmlDocStatement API to construct structured XML documentation. This ensures proper XML rendering without encoding issues. - Created BuildEnhancedXmlDocs method that constructs XmlDocStatement objects - Builds list with items for Request Path, Operation Id, API Version, and Resource - Uses XmlDocSummaryStatement to properly wrap the summary content - XmlDocs.Update() is called to update the summary with structured statements This addresses the reviewer's feedback to use XmlDocStatement construction. Co-authored-by: live1206 <[email protected]> * Regenerate test projects with proper XML documentation After merging main branch and resolving conflicts, regenerated all test projects to reflect the updated generator changes. The XML documentation now uses proper XmlDocStatement construction, resulting in correctly formatted XML tags instead of HTML-encoded entities. Generated documentation now properly shows: - <list type="bullet"> instead of &lt;list type="bullet"&gt; - <item>, <term>, <description> tags without encoding - Properly formatted operation metadata (Request Path, Operation Id, API Version, Resource) Co-authored-by: live1206 <[email protected]> * Remove dead code and simplify BuildEnhancedXmlDocs - Removed BuildEnhancedDescription method which was a no-op - Changed line 87 to use original assignment: _description = description ?? _convenienceMethod.Signature.Description - Changed BuildEnhancedXmlDocs return type from XmlDocProvider? to void since return value is not used - Simplified method by directly updating existingXmlDocs instead of returning it Addresses reviewer feedback to remove redundant code. Co-authored-by: live1206 <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: live1206 <[email protected]>
1 parent 1e49655 commit 91b92c2

25 files changed

+2462
-129
lines changed

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

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Microsoft.TypeSpec.Generator.Statements;
1919
using System;
2020
using System.Collections.Generic;
21+
using System.Linq;
2122
using System.Threading.Tasks;
2223
using static Microsoft.TypeSpec.Generator.Snippets.Snippet;
2324

@@ -95,6 +96,65 @@ public ResourceOperationMethodProvider(
9596
_bodyStatements = BuildBodyStatements();
9697
}
9798

99+
/// <summary>
100+
/// Builds enhanced XML documentation with structured XmlDocStatement objects for proper XML rendering.
101+
/// </summary>
102+
private static void BuildEnhancedXmlDocs(InputServiceMethod serviceMethod, FormattableString? baseDescription, TypeProvider enclosingType, XmlDocProvider? existingXmlDocs)
103+
{
104+
if (existingXmlDocs == null)
105+
{
106+
return;
107+
}
108+
109+
var operation = serviceMethod.Operation;
110+
111+
// Build list items for the operation metadata
112+
var listItems = new List<XmlDocStatement>();
113+
114+
// Request Path item
115+
listItems.Add(new XmlDocStatement("item", [],
116+
new XmlDocStatement("term", [$"Request Path"]),
117+
new XmlDocStatement("description", [$"{operation.Path}"])));
118+
119+
// Operation Id item
120+
listItems.Add(new XmlDocStatement("item", [],
121+
new XmlDocStatement("term", [$"Operation Id"]),
122+
new XmlDocStatement("description", [$"{operation.Name}"])));
123+
124+
// API Version item (if available)
125+
var apiVersionParam = operation.Parameters.FirstOrDefault(p => p.IsApiVersion);
126+
if (apiVersionParam != null && apiVersionParam.DefaultValue?.Value != null)
127+
{
128+
listItems.Add(new XmlDocStatement("item", [],
129+
new XmlDocStatement("term", [$"Default Api Version"]),
130+
new XmlDocStatement("description", [$"{apiVersionParam.DefaultValue.Value}"])));
131+
}
132+
133+
// Resource item (if enclosing type is a ResourceClientProvider)
134+
if (enclosingType is ResourceClientProvider resourceClient)
135+
{
136+
listItems.Add(new XmlDocStatement("item", [],
137+
new XmlDocStatement("term", [$"Resource"]),
138+
new XmlDocStatement("description", [$"{resourceClient.Type:C}"])));
139+
}
140+
141+
// Create the list statement
142+
var listStatement = new XmlDocStatement($"<list type=\"bullet\">", $"</list>", [], innerStatements: listItems.ToArray());
143+
144+
// Build the complete summary with base description and metadata list
145+
var summaryContent = new List<FormattableString>();
146+
if (baseDescription != null)
147+
{
148+
summaryContent.Add(baseDescription);
149+
}
150+
151+
// Create summary statement with the list as inner content
152+
var summaryStatement = new XmlDocSummaryStatement(summaryContent, listStatement);
153+
154+
// Update the XmlDocs with the new summary
155+
existingXmlDocs.Update(summary: summaryStatement);
156+
}
157+
98158
private static void InitializeLroFlags(
99159
in InputServiceMethod serviceMethod,
100160
in bool forceLro,
@@ -131,10 +191,19 @@ protected virtual CSharpType BuildReturnType()
131191

132192
public static implicit operator MethodProvider(ResourceOperationMethodProvider resourceOperationMethodProvider)
133193
{
134-
return new MethodProvider(
194+
var methodProvider = new MethodProvider(
135195
resourceOperationMethodProvider._signature,
136196
resourceOperationMethodProvider._bodyStatements,
137197
resourceOperationMethodProvider._enclosingType);
198+
199+
// Add enhanced XML documentation with structured tags
200+
BuildEnhancedXmlDocs(
201+
resourceOperationMethodProvider._serviceMethod,
202+
resourceOperationMethodProvider._convenienceMethod.Signature.Description,
203+
resourceOperationMethodProvider._enclosingType,
204+
methodProvider.XmlDocs);
205+
206+
return methodProvider;
138207
}
139208

140209
protected virtual MethodBodyStatement[] BuildBodyStatements()

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

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

0 commit comments

Comments
 (0)