Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mike-loux-planview opened this issue Apr 24, 2023 · 1 comment
Labels
help-wanted A change up for grabs for contributions from the community

Comments

@mike-loux-planview
Copy link

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
Copy link

Havunen commented Feb 19, 2024

This is supported in DotSwashbuckle 3.0.4
image

@martincostello martincostello added the help-wanted A change up for grabs for contributions from the community label Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help-wanted A change up for grabs for contributions from the community
Projects
None yet
Development

No branches or pull requests

3 participants