I want to add a bunch of JSON examples to my controllers, but I don't want to swell the controller source file with a bunch of XML.
Fortunately, XML Doc Comments support the use of an include tag to reference a separate file and XPath. So instead of having:
/// <summary>Summary goes here</summary>
/// <remarks>Remarks go here</remarks>
Obviously that is a very contrived example, but when you start adding examples and parameters and other things to the XML file, it can get pretty big (and if you do multiple examples in the remarks section like I do, it's a lot better off in a separate file).
So that all sounds great, except that Swashbuckle doesn't render the external comments in the UI.
I have created a quick ASP.NET Core WebApi project in .NET 7 that reproduces the issue and have attached it here.
In short, I created a PingController that has 2 methods - one with the docs embedded, and one with the docs referenced. The first one renders; the second one does not:
I verified that the references do work by newing up the controller in a code snippet and verifying that when I hover over the call to the embedded controller the docs appear in IntelliSense:
And I verified that the docs are pulled into the generated .xml file on build:
<member name="M:XmlDocExamples.Controllers.PingController.ReferencedPing">
<ReferencedPing>
<summary>Does a ping.</summary>
<returns>Returns a pong.</returns>
<remarks>XML doc comments are included from a separate file.</remarks>
</ReferencedPing>
</member>
I did notice that the generated doc has an extra tag layer around the referenced comments, and maybe that is causing a problem? But I don't know how to not generate that, and if Visual Studio supports it, it seems to be working as designed.
I want to add a bunch of JSON examples to my controllers, but I don't want to swell the controller source file with a bunch of XML.
Fortunately, XML Doc Comments support the use of an
include
tag to reference a separate file and XPath. So instead of having:I can do the following:
Where the XML file would look like the following
Obviously that is a very contrived example, but when you start adding examples and parameters and other things to the XML file, it can get pretty big (and if you do multiple examples in the
remarks
section like I do, it's a lot better off in a separate file).So that all sounds great, except that Swashbuckle doesn't render the external comments in the UI.
I have created a quick ASP.NET Core WebApi project in .NET 7 that reproduces the issue and have attached it here.
In short, I created a
PingController
that has 2 methods - one with the docs embedded, and one with the docs referenced. The first one renders; the second one does not:I verified that the references do work by newing up the controller in a code snippet and verifying that when I hover over the call to the embedded controller the docs appear in IntelliSense:
And I verified that the docs are pulled into the generated .xml file on build:
I did notice that the generated doc has an extra tag layer around the referenced comments, and maybe that is causing a problem? But I don't know how to not generate that, and if Visual Studio supports it, it seems to be working as designed.
mjl-XmlDocExample.zip