Leverage MultipleApiVersions in Swagger with attribute versioning

后端 未结 2 1853
一生所求
一生所求 2021-01-04 14:06

Is it possible to leverage MultipleApiVersions in Swagger UI / Swashbuckle when using attribute routing?

Specifically, I implemented versioning by:



        
2条回答
  •  -上瘾入骨i
    2021-01-04 14:53

    .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");
            }
            ))
    

提交回复
热议问题