Swagger Documentation with Swashbuckle
March 13, 2017
I wanted to document my code such that I get good quality swagger documentation in the test web pages. I'm using Swashbuckle in C# to document a webapi interface.
Project Configuration
You need to configure the project so that it will output documentation (like JavaDoc) to XML files alongside the built project.
For each project you have documentation in, right click, properties and navigate to the build
tab. Check the XML Documentation File
option.
Swagger Configuration
Add the following in SwaggerConfig.cs
to enable reading of the XML files created above:
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory; var commentsFileName = Assembly.GetExecutingAssembly().GetName().Name + ".XML"; var commentsFile = Path.Combine(baseDirectory, "bin", commentsFileName); c.IncludeXmlComments(commentsFile);