Skip to content

Commit 803ae9c

Browse files
committed
react to feedback
1 parent a73d57a commit 803ae9c

File tree

1 file changed

+20
-32
lines changed

1 file changed

+20
-32
lines changed

aspnetcore/fundamentals/openapi/openapi-comments.md

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ uid: fundamentals/openapi/aspnet-openapi-xml
1111
<!-- backup author: rick-anderson -->
1212
# OpenAPI XML documentation comment support in ASP.NET Core
1313

14-
ASP.NET Core will include metadata from XML doc comments in the generated OpenAPI document. No changes are required in app code to enable XML documentation comment support, but the project must be configured to generate the XML documentation file. ASP.NET Core automatically detects XML documentation comments in the application assembly and any referenced assemblies that have XML documentation enabled.
14+
OpenAPI XML documentation 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.
1515

1616
ASP.NET Core processes [XML documentation tags](https://learn.microsoft.com/dotnet/csharp/language-reference/xmldoc/recommended-tags) like: `<c>`, `<code>`, `<list>`, `<para>`, `<paramref>`, `<typeparamref>`, `<see>`, and `<seealso>`.
1717
For XML documentation tags that use references to other elements, like `<see cref="SomeOtherType">`, the implementation strips out the XML tag and maps the reference to plain text for inclusion in the OpenAPI document.
@@ -52,7 +52,7 @@ To turn off XML documentation integration, remove the source generator from the
5252

5353
## Source generator implementation notes
5454

55-
The source generator implementation is open-source and can be found in the [ASP.NET Core repository](https://github.com/dotnet/aspnetcore/tree/main/src/OpenApi/gen).
55+
5656

5757
The XML documentation feature is implemented as a source generator. The source generator analyzes XML documentation comments at compile time and injects code that translates these comments into OpenAPI metadata. The [`XmlCommentGenerator`](https://source.dot.net/#Microsoft.AspNetCore.OpenApi.SourceGenerators/XmlCommentGenerator.cs,30eb0aa73ef6306a) extracts XML comments from two sources:
5858

@@ -68,27 +68,28 @@ XML comments are parsed into structured `XmlComment` objects with:
6868
* Response documentation with status codes and descriptions.
6969
* Support for examples and deprecated markers.
7070

71+
### `<inheritdoc/>`
7172

72-
### Support for `<inheritdoc/>`
73+
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:
7374

74-
<!-- original - review my change
75-
`<inheritdoc />` tags present an important opportunity because they indicate that comments must be resolved from a base class or implemented interface.
76-
The source generator uses its knowledge of the symbol's present in the compilation to discover base classes and interfaces associated with the symbol a given `<inheritdoc />` is placed on and supports resolving them automatically
77-
-->
75+
* Base classes
76+
* Implemented interfaces
77+
* Base methods for overrides
7878

79-
`<inheritdoc />` tags indicate that comments must be resolved from a base class or implemented interface. When `<inheritdoc />` is placed on a symbol, The source generator:
79+
When `<inheritdoc />` is placed on a symbol, The source generator:
8080

8181
* Uses its knowledge of the symbol in the compilation to discover base classes and interfaces associated with the symbol.
8282
* Supports resolving them automatically
83+
* Substitutes generic type parameters in inherited documentation comments, preserving type references across inheritance boundaries.
8384

8485
The automatic resolution behavior is currently available for XML documentation comments that exist in the assembly under compilation, and ***not*** XML documentation tags that are in referenced projects or packages. In the later scenario, XML documentation comments:
8586

8687
* Are only presented as text.
87-
* There's no trivial strategy for:
88+
* Don't provide a trivial strategy for:
8889
* Associating the text content to compilation symbols.
8990
* Developing an understanding of the inheritance hierarchy associated with the types.
9091

91-
### Member Identification
92+
<!-- ### Member identification - `MemberKey` removed in preview 3.
9293
9394
The source generator discovers XML comments statically and emits code that applies them to the document dynamically at runtime. The [`MemberKey`](https://source.dot.net/#Microsoft.AspNetCore.OpenApi.SourceGenerators/XmlComments/MemberKey.cs,d182ed147edb11d2) class acts as a bridge between compile-time and runtime representations of the same concept. It's a unique identifier for types, methods, and properties that works across:
9495
@@ -105,17 +106,13 @@ internal sealed record MemberKey(
105106
string? Name,
106107
string? ReturnType,
107108
string[]? Parameters) : IEquatable<MemberKey>
108-
```
109+
``` -->
109110

110111
### Code Generation
111112

112113
The generator emits code that contains:
113114

114115
* A cache of XML comments mapped to member identifiers:
115-
<!-- REVIEW: In additon to the following, provide a concret example -->
116-
```csharp
117-
_cache.Add(new MemberKey(/*...*/), new XmlComment(/*...*/));
118-
```
119116
* OpenAPI transformer implementations:
120117
* [`XmlCommentOperationTransformer`](https://github.com/dotnet/aspnetcore/blob/main/src/OpenApi/gen/XmlCommentGenerator.Emitter.cs#L229): Applies comments to API operations (methods).
121118
* [`XmlCommentSchemaTransformer`](https://github.com/dotnet/aspnetcore/blob/main/src/OpenApi/gen/XmlCommentGenerator.Emitter.cs#L308): Applies comments to data models (types).
@@ -159,11 +156,11 @@ When the generated code runs:
159156

160157
The generator processes standard XML code comments and adds them to the generated OpenAPI documentation.
161158

162-
## Frequently Asked Questions
159+
<!-- ## Frequently Asked Questions
163160
164-
### What is the OpenAPI XML documentation support feature?
161+
Moved to intro ### What is the OpenAPI XML documentation support feature?
165162
166-
The feature automatically extracts XML documentation comments from code and uses them to populate OpenAPI documentation. API documentation is generated directly from code comments, keeping them in sync.
163+
The feature automatically extracts XML documentation comments from code and uses them to populate OpenAPI documentation. API documentation is generated directly from code comments, keeping them in sync. -->
167164

168165
### How does the XML documentation support work?
169166

@@ -226,21 +223,11 @@ To add examples to documentation, use the [`<example>`](/dotnet/csharp/language-
226223
/// <param name="id" example="42">The unique identifier</param>
227224
```
228225

229-
### Document inheritance via `<inheritdoc/>` tags
230-
231-
The generator supports [`<inheritdoc>`](/dotnet/csharp/language-reference/xmldoc/recommended-tags#inheritdoc) tags, which inherit documentation from *as long as they exist in the compilation assembly*:
232-
233-
* Base classes
234-
* Implemented interfaces
235-
* Base methods for overrides
236-
237-
### How are generic type parameters handled when inheriting documentation?
238-
239-
The source generator substitutes generic type parameters in inherited documentation comments, preserving type references across inheritance boundaries.
226+
<!-- move FAQ to topic -->
240227

241-
### How does the source generator identify and track API members?
228+
### How does the source generator identify and track API members? zzz move to impl
242229

243-
It uses the [`MemberKey`](https://github.com/dotnet/aspnetcore/blob/main/src/OpenApi/gen/XmlComments/MemberKey.cs) class to create a unique identifier for each API member that encodes:
230+
The source generator uses an [`XmlComment Cache`](https://github.com/dotnet/aspnetcore/blob/main/src/OpenApi/gen/XmlCommentGenerator.Emitter.cs#L84-L96) class to identify and track API members. It create a unique identifier for each API member that encodes:
244231

245232
* Declaring and property types.
246233
* Method names.
@@ -303,7 +290,8 @@ Navigate to [http://localhost:5052/](http://localhost:5052/) to view the Scalar
303290

304291
## Additional resources
305292

306-
* [Source generator implementation notes](https://github.com/captainsafia/aspnet-openapi-xml#implementation-notes)
293+
* The source generator implementation can be found in the [ASP.NET Core repository](https://github.com/dotnet/aspnetcore/tree/main/src/OpenApi/gen).
294+
[Source generator implementation notes](https://github.com/captainsafia/aspnet-openapi-xml#implementation-notes)
307295
* <xref:fundamentals/openapi/aspnetcore-openapi>
308296
* <xref:fundamentals/openapi/using-openapi-documents>
309297
* <xref:fundamentals/openapi/openapi-tools>

0 commit comments

Comments
 (0)