Skip to content

Commit d72564a

Browse files
Copilotwadepickettmikekistler
authored
Integrate .NET 10 XML comment improvements into OpenAPI documentation seamlessly (#35996)
* Initial plan * Add .NET 10 XML comment generator improvements to OpenAPI docs Co-authored-by: wadepickett <[email protected]> * Update ms.date metadata to 08/25/2025 as requested Co-authored-by: wadepickett <[email protected]> * Reintegrate .NET 10 improvements seamlessly into existing sections Co-authored-by: wadepickett <[email protected]> * Update aspnetcore/fundamentals/openapi/openapi-comments.md Removed comment about back up author * Remove code comments from XML configuration example as they are not localized Co-authored-by: wadepickett <[email protected]> * Enhance OpenAPI comments with .NET 10 improvements Revert to .NET 10 specific summary * Update aspnetcore/fundamentals/openapi/openapi-comments.md * Update aspnetcore/fundamentals/openapi/openapi-comments.md removed extra line * Update aspnetcore/fundamentals/openapi/openapi-comments.md Edit and clean up for XML comment gen paragraph. * Update aspnetcore/fundamentals/openapi/openapi-comments.md Co-authored-by: Mike Kistler <[email protected]> * Apply suggestions from code review Added great suggestions from Mike. Co-authored-by: Mike Kistler <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: wadepickett <[email protected]> Co-authored-by: Wade Pickett <[email protected]> Co-authored-by: Mike Kistler <[email protected]>
1 parent b60cb8e commit d72564a

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

aspnetcore/fundamentals/openapi/openapi-comments.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
title: ASP.NET Core OpenAPI XML documentation comment support in ASP.NET Core
3+
ai-usage: ai-assisted
34
author: captainsafia
45
description: Learn how to integrate XML documentation comments on types by OpenAPI document generation in ASP.NET Core.
5-
ms.author: safia
66
monikerRange: '>= aspnetcore-10.0'
7+
ms.author: safia
78
ms.custom: mvc
8-
ms.date: 04/15/2025
9+
ms.date: 08/25/2025
910
uid: fundamentals/openapi/aspnet-openapi-xml
1011
---
11-
<!-- backup author: rick-anderson -->
1212
# OpenAPI XML documentation comment support in ASP.NET Core
1313

1414
ASP.NET Core XML documentation processing extracts code comments automatically to populate API documentation, ensuring the code and documentation remain synchronized. Metadata from XML documentation comments is included in the generated OpenAPI document without requiring changes to the app code, as long as the project is configured to generate the XML documentation file. XML documentation comments are automatically detected in the application assembly and referenced assemblies with XML documentation enabled.
@@ -106,6 +106,21 @@ To include XML documentation files from referenced assemblies, add them as `Addi
106106
</ItemGroup>
107107
```
108108

109+
XML doc comment processing can be configured to access XML comments in other assemblies. This is useful for generating documentation for types that are defined outside the current assembly, such as the `ProblemDetails` type in the `Microsoft.AspNetCore.Http` namespace. This configuration is done with directives in the project build file. The following example shows how to configure the XML comment generator to access XML comments for types in the `Microsoft.AspNetCore.Http` assembly, which includes the `ProblemDetails` class:
110+
111+
```xml
112+
<Target Name="AddOpenApiDependencies" AfterTargets="ResolveReferences">
113+
<ItemGroup>
114+
<AdditionalFiles
115+
Include="@(ReferencePath->'
116+
%(RootDir)%(Directory)%(Filename).xml')"
117+
Condition="'%(ReferencePath.Filename)' ==
118+
'Microsoft.AspNetCore.Http.Abstractions'"
119+
KeepMetadata="Identity;HintPath" />
120+
</ItemGroup>
121+
</Target>
122+
```
123+
109124
#### Disabling XML documentation support
110125

111126
To turn off XML documentation integration, remove the source generator from the `Analyzers` item group. Removing the source generator prevents it from being used during compilation.
@@ -130,6 +145,14 @@ XML comments are parsed into structured `XmlComment` objects with:
130145
* Response documentation with status codes and descriptions.
131146
* Support for examples and deprecated markers.
132147

148+
### Handling of complex types
149+
150+
XML comment processing produces accurate and complete OpenApi descriptions for a wide range of types and supports complex scenarios. But if an error is encountered when processing a complex types, the process bypasses the type gracefully.
151+
152+
In this way, scenarios that might have resulted in build errors now simply result in missing metadata, helping to avoid build failures.
153+
154+
XML documentation comments from referenced assemblies are correctly merged even when their documentation IDs include return type suffixes. As a result, all valid XML comments are reliably included in generated OpenAPI documentation, improving documentation accuracy and completeness for APIs using referenced assemblies.
155+
133156
### `<inheritdoc/>`
134157

135158
The generator supports [`<inheritdoc>`](/dotnet/csharp/language-reference/xmldoc/recommended-tags#inheritdoc) tags, which inherit documentation *as long as they exist in the compilation assembly*. `<inheritdoc />` tags indicate that comments must be resolved from:

0 commit comments

Comments
 (0)