using System.Web.Http; using Swashbuckle.Swagger; namespace MyWebApi { public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.SetDocumentationProvider(new XmlCommentsFilePathProvider()); } } public class XmlCommentsFilePathProvider : IDocumentationProvider { public string GetDocumentation(HttpControllerDescriptor controllerDescriptor) { // logic to get documentation for controller } public string GetDocumentation(HttpActionDescriptor actionDescriptor) { // logic to get documentation for action } } }
using System.Web.Http; using Swashbuckle.Application; namespace MyWebApi { public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.SetDocumentationProvider(new XmlCommentsFilePathProvider()); config.EnableSwagger(c => c.SingleApiVersion("v1", "My Web API")); config.EnableSwaggerUi(); } } public class XmlCommentsFilePathProvider : IDocumentationProvider { public string GetDocumentation(HttpControllerDescriptor controllerDescriptor) { // logic to get documentation for controller } public string GetDocumentation(HttpActionDescriptor actionDescriptor) { // logic to get documentation for action } } }This example also uses the Swashbuckle.Swagger package, but also enables the Swagger UI to provide an interactive experience for exploring and testing endpoints. The config.EnableSwagger and config.EnableSwaggerUi methods are added to the HttpConfiguration object to enable the Swagger UI.