domaindrivendev / Swashbuckle.AspNetCore

Swagger tools for documenting API's built on ASP.NET Core
MIT License
5.25k stars 1.31k forks source link

XML Doc comments referenced via `include` tag are not pulled into Swagger UI #2639

Open mike-loux-planview opened 1 year ago

mike-loux-planview commented 1 year ago

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>

I can do the following:

/// <include file='./MyController.xml' path='/MyController/MyEndpoint'/>

Where the XML file would look like the following

<?xml version="1.0" encoding="utf-8" ?>
<MyController>
  <MyEndpoint>
    <summary>Summary goes here</summary>
    <remarks>Remarks go here</remarks>
  </MyEndpoint>
</MyController>

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:

image

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:

image

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.

mjl-XmlDocExample.zip

Havunen commented 8 months ago

This is supported in DotSwashbuckle 3.0.4 image