JARVIS
JARVIS

Reputation: 855

WebApi controller summary is not showing on Swagger documentation

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.

Upvotes: 33

Views: 42853

Answers (8)

Egor Sindeev
Egor Sindeev

Reputation: 159

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.

Upvotes: 6

Ambert Yang
Ambert Yang

Reputation: 11

now, in .net core is easy

config.UseControllerSummaryAsTagDescription = true;

Upvotes: 1

Sumeet
Sumeet

Reputation: 642

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

Upvotes: 45

ahaliav fox
ahaliav fox

Reputation: 2247

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>

Upvotes: 2

Asad Ullah
Asad Ullah

Reputation: 2337

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);
});

Upvotes: 16

Palash Roy
Palash Roy

Reputation: 1765

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

Upvotes: 20

Elias Platek
Elias Platek

Reputation: 1114

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.

Upvotes: 2

levent
levent

Reputation: 3634

Is there following code in the SwaggerConfig class?

GlobalConfiguration.Configuration 
            .EnableSwagger(c =>
                {

                    c.IncludeXmlComments(string.Format(@"{0}\bin\YourAssemlyName.XML", System.AppDomain.CurrentDomain.BaseDirectory));  

Upvotes: 5

Related Questions