I created a new asp.net web api 2 project in visual studio 2015 using ASP.NET Web API 2.1 Custom Route Attributes .
I am using Swagger (SwashBuckle 5.0) for API documentation and wanted to have documentation for the version that I was able to get this document, but still showing the same xml comments from both versions.
In the xml comments on api / view for versions 1 and 2 there are several different ones that do not appear in swagger ui.
Version 1
Version 2

public class SwaggerConfig { public static void Register() { var thisAssembly = typeof(SwaggerConfig).Assembly; GlobalConfiguration.Configuration .EnableSwagger(c => { c.MultipleApiVersions( (apiDesc, targetApiVersion) => ResolveVersionSupportByRouteConstraint(apiDesc, targetApiVersion), (vc) => { vc.Version("2", "Swagger API V2"); vc.Version("1", "Swagger API V1"); }); c.IncludeXmlComments(GetXmlCommentsPath()); }) .EnableSwaggerUi(c => { c.EnableDiscoveryUrlSelector(); }); } private static string GetXmlCommentsPath() { return String.Format(@"{0}\bin\ChartOfAccounts.Api.XML", AppDomain.CurrentDomain.BaseDirectory); } private static bool ResolveVersionSupportByRouteConstraint(ApiDescription apiDesc, string targetApiVersion) { var attr = apiDesc.ActionDescriptor.GetCustomAttributes<VersionedRoute>().FirstOrDefault(); if (attr == null) { return true; } int targetVersion; if (int.TryParse(targetApiVersion, out targetVersion)) { return attr.AllowedVersion == targetVersion; }; return true; } }
Controller version 1
[VersionedRoute("api/view", 1)] public class ViewController : ApiController { private IChartManager _chartManager; public ViewController(IChartManager chartManager) { _chartManager = chartManager; }
API controller v2
[VersionedRoute("api/view", 2)] public class Viewv2Controller : ApiController { private IChartManager _chartManager; public Viewv2Controller(IChartManager chartManager) { _chartManager = chartManager; }
source share