Is it possible to leverage MultipleApiVersions in Swagger UI / Swashbuckle when using attribute routing?
Specifically, I implemented versioning by:
using System.Web.Http;
namespace RESTServices.Controllers.v1
{
[Route("api/v1/Test")]
public class TestV1Controller : ApiController
{ ... }
Version 2 would be in a v2 namespace. In a controller named TestV2Controller. The route would have v2 in it.
Is it possible to pass a lambda in that will allow this? I found a sample lambda online which compiled, but then Swagger stopped working completely. Couldn't hit breakpoints or see Swagger in the browser.
.EnableSwagger(c => c.MultipleApiVersions(
(apiDesc, version) =>
{
var path = apiDesc.RelativePath.Split('/');
var pathVersion = path[1];
return CultureInfo.InvariantCulture.CompareInfo.IndexOf(pathVersion, version, CompareOptions.IgnoreCase) >= 0;
},
vc =>
{
vc.Version("v2", "Swashbuckle Dummy API V2"); //add this line when v2 is released
// ReSharper disable once ConvertToLambdaExpression
vc.Version("v1", "Swashbuckle Dummy API V1");
}
))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With