Include XML Comments In Swagger under ASP.NET Core 2.2

Swagger's minimum configuration is nice to start, but let's add some more customization.

Before you start reading this article, we recommend looking at this article Build Up Swagger In ASP.Net Core 2.2 Web API.

XML Documentation

First, enable the creation of XML documentation. In the Solution Explorer, right-click the Web API project and click Properties.

Click the Build tab and navigate to Output. Make sure that the XML documentation file option is checked. You can leave the default file path.

Include XML Comments in Swagger under ASP.NET Core 2.2

Next, we need to make some changes to our Startup.cs file to tell swagger to use those comments.

Include XML Comments in Swagger under ASP.NET Core 2.2

Writing XML Comments

Back in our ValuesController, let's write some XML comments for methods. Here's what the sample project has:

Include XML Comments in Swagger under ASP.NET Core 2.2

Here are the tags in use,

summary

A high-level summary of what the 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.

Once all of this is n place, we are ready to run the project.

Include XML Comments in Swagger under ASP.NET Core 2.2

The source code for this tutorial is available on GitHub.

Did you catch something I did wrong, or can you improve my implementation? Let me know in the comments!

Happy Documenting!


Similar Articles