Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 299
JARVIS Avatar asked Feb 03 '17 07:02

JARVIS


People also ask

How do you show description in Swagger?

1 - Open the Properties dialog for your project, click the "Build" tab and ensure that "XML documentation file" is checked. This will produce a file containing all XML comments at build-time. At this point, any classes or methods that are NOT annotated with XML comments will trigger a build warning.

How do I add a Swagger controller?

Go to controllers (right click) > Add > Controllers.

How do I get Swagger API document?

Head over to Swagger Inspector, and insert the end point of the resource you want to have documented. You can then navigate to the right panel from the History section of Swagger Inspector, and click "Create API definition" to create the OAS definition.

Why we choose Swagger for web API?

That’s why we choose Swagger, also known as OpenAPI. It provides all such benefits like interactive documentation, client SDK generation, and API discoverability. In this article, I am explaining a few basic configurations of Swagger in ASP.NET Core applications. We can add more additional features on the Web API using Swagger.

Is it possible to display the controller summary in API?

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. Show activity on this post.

How to integrate SwaggerHub with swagger Inspector?

The integration allows developers to automatically host and visualize their API documentation on SwaggerHub to enable API discovery and consumption by internal and external stakeholders. Head over to Swagger Inspector, and insert the end point of the resource you want to have documented.

What is Swagger specification?

Swagger Specification is an important part of the Swagger flow. By default, a document named swagger.jsonis generated by the Swagger tool which is based on our API. It describes the capabilities of our API and how to access it via HTTP. Swagger UI Swagger UI offers a web-based UI that provides information about the service.


1 Answers

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://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-5.0&tabs=visual-studio

like image 157
Sumeet Avatar answered Sep 21 '22 18:09

Sumeet