29

When I enable this documentation feature through Swagger I'm able to see all kind of information about my documentation but there is no details about my Controller name detail/description.

How to show controller documentation content like below example?

/// <summary> 

/// Represents the alert api controller class.

/// <summary>

public class XYZController : ApiController
{

}

On enabling swagger I'm not able to see this content any where Represents the XYZ api controller class. here

However I able to see my all method description.

Veve
  • 6,643
  • 5
  • 39
  • 58
JARVIS
  • 765
  • 1
  • 8
  • 28

8 Answers8

39

1.) Right click the project and Edit projname.csproj Add the following

<PropertyGroup>
  <GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

2.) Add the following to AddSwaggerGen in ConfigureServices

  // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);

For more details goto:

https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-5.0&tabs=visual-studio

8protons
  • 3,591
  • 5
  • 32
  • 67
Sumeet
  • 574
  • 5
  • 5
20

you need to add IncludeXmlComments extension in AddSwaggerGen as below:

 services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1.0", new Info
            {
                Title = "My APIs",
                Version = "v1.0",
                Description = "REST APIs "
            });

            **// Set the comments path for the Swagger JSON and UI.**
            var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
            var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
            c.IncludeXmlComments(xmlPath);            
        });

For more details refer here

Palash Roy
  • 1,547
  • 1
  • 15
  • 11
12

This is possible, See @Liversage answer on this page https://github.com/domaindrivendev/Swashbuckle/issues/572

services.AddSwaggerGen(c =>
{
    var xmlPath = ...;
    c.IncludeXmlComments(xmlPath, includeControllerXmlComments: true);
});
Asad Ullah
  • 2,257
  • 2
  • 24
  • 23
5

Is there following code in the SwaggerConfig class?

GlobalConfiguration.Configuration 
            .EnableSwagger(c =>
                {

                    c.IncludeXmlComments(string.Format(@"{0}\bin\YourAssemlyName.XML", System.AppDomain.CurrentDomain.BaseDirectory));  
levent
  • 3,464
  • 1
  • 12
  • 22
5

As some guys above have reply already, I guess the question was about this:

var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
s.IncludeXmlComments(xmlPath, includeControllerXmlComments: true);

set includeControllerXmlComments: true will allow to take summary of controllers.

Egor Sindeev
  • 149
  • 2
  • 2
2

I think this is related to the following issue : https://github.com/domaindrivendev/Swashbuckle/issues/572

It is currently not possible to display the controller summary, according to the maintainer:

The reason this has been low on the priority list is because it's not something I've run into issues with. You can absolutely describe what every action in your API does using XML comments on your actions.

Elias Platek
  • 1,074
  • 1
  • 9
  • 16
2

in my case, I only needed to mark to use the XML document enter image description here

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>C:...\CertReports.Host.xml</DocumentationFile>
ahaliav fox
  • 2,217
  • 22
  • 21
1

now, in .net core is easy

config.UseControllerSummaryAsTagDescription = true;