Document Your Existing API’s With (Open API) Specification in ASP.NET Core
API 📗 Swagger

In this article, we will learn how to document our already existing APIs with .Net and.Net Core. Many developers absolutely deplore writing documentation. It’s boring to put all these things together in a document by manually writing them. To overcome this we have Swagger to implement documentation and it’s an open-source API documentation tool.

Packages required to configure Swagger,

Swashbuckle.AspNetCore (latest version) — This package adds Swagger and Swagger UI and other libraries to make it easy for us to create API documentation.

Step 1

After installing the package to the respective project, here I am sharing the screenshot for your reference if you are new to Swagger in ASP.Net Core

Fig-1

Step 2 -Setup

We need to enable our project to generate XML comments. The comments come from Triple-slash (///) comments throughout the code.

First, in the project properties, check the box labeled “Generate XML Documentation”

Right Click on the Solution and click on the Properties

Fig-2

You will probably also want to suppress warning 1591, which will now give warnings about any method, class, or field that doesn’t have triple-slash comments.

Fig-3

Step 3 -Configure Swagger

Startup.cs

launchSettings.json

XML Comments

In our XML Comments for methods.

WeatherController.cs

Here are XML nodes in use:

Summary: A high-level summary of what our method /class/field is or does.

remarks: Additional detail about the method/class/field

param: A parameter to the method, and what it represents

returns: A description of what the method returns.

Output — View Swagger

Fig-4

Here is a clear description of what is what in Swagger UI

Fig-5

Thank you for reading, please let me know your questions, thoughts, or feedback in the comments section. I appreciate your feedback and encouragement.

Move your project on next level by hiring skilled and seasoned ASP.NET core developers.

Keep Learning and Exploring…. !!!
['Jay Krishna Reddy']
['Startup', 'Tech', 'Software Development', 'Programming', 'Technology']