在扬鞭杠杆MultipleApiVersions带属性的版本

在扬鞭杠杆MultipleApiVersions带属性的版本

本文介绍了在扬鞭杠杆MultipleApiVersions带属性的版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使用属性布线时利用MultipleApiVersions在扬鞭UI / Swashbuckle?

具体来说,我实现了通过版本:

使用System.Web.Http

 命名空间RESTServices.Controllers.v1
{
    [路线(API / V1 /测试)]
    公共类TestV1Controller:ApiController
    {...}

2版将在一个V2命名空间。在一个名为TestV2Controller控制器。该航线将有V2在里面。

是否有可能通过在一个lambda会允许这样做?我发现了一个编译样本拉姆达网上,但随后扬鞭完全停止工作。无法命中断点或看到扬鞭在浏览器中。


解决方案

  .EnableSwagger(C => c.MultipleApiVersions(
        (apiDesc,版本)= GT;
        {
            VAR路径= apiDesc.RelativePath.Split('/');
            VAR pathVersion =路径[1];            返回CultureInfo.InvariantCulture.CompareInfo.IndexOf(pathVersion,版本,CompareOptions.IgnoreCase)GT; = 0;
        },
        VC =>
        {
            vc.Version(V2,Swashbuckle虚拟API V2); // V2被释放时,加入这行            //禁用ReSharper的一次ConvertToLambdaEx pression
            vc.Version(V1,Swashbuckle虚拟API V2);
        }
        ))

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

这篇关于在扬鞭杠杆MultipleApiVersions带属性的版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 09:03