简体   繁体   English

Swagger UI - 使用 Microsoft.AspNet.WebApi.Versioning 时的 Web API 版本控制

[英]Swagger UI - Web API versioning when using Microsoft.AspNet.WebApi.Versioning

We are using Web API 2 on our project with Swagger .我们在Swagger项目中使用Web API 2 My problem is that when Microsoft.AspNet.WebApi.Versioning is applied as following:我的问题是,当Microsoft.AspNet.WebApi.Versioning应用如下:

在此处输入图片说明

the Swagger UI is ignoring the fact that now I have version in my API which needs to be provided. Swagger UI忽略了这样一个事实,即现在我的 API 中有需要提供的版本。

I looked at several examples but none seem to address this issue in a satisfying manner.我看了几个例子,但似乎没有一个能以令人满意的方式解决这个问题。

How do I force Swagger to let me add the API version or just add the version number automatically to the URL?如何强制 Swagger 让我添加 API 版本或仅将版本号自动添加到 URL?

Swagger configuration so far:到目前为止的 Swagger 配置:

GlobalConfiguration.Configuration
                .EnableSwagger(c =>
                {

                    c.SingleApiVersion("v1", "MoovShack.ServerApi");

                    // If your API has multiple versions, use "MultipleApiVersions" instead of "SingleApiVersion".
                    // In this case, you must provide a lambda that tells Swashbuckle which actions should be
                    // included in the docs for a given API version. Like "SingleApiVersion", each call to "Version"
                    // returns an "Info" builder so you can provide additional metadata per API version.
                    //
                    //c.MultipleApiVersions(
                    //    (apiDesc, targetApiVersion) => ResolveVersionSupportByRouteConstraint(apiDesc, targetApiVersion),
                    //    (vc) =>
                    //    {
                    //        vc.Version("v2", "Swashbuckle Dummy API V2");
                    //        vc.Version("v1", "Swashbuckle Dummy API V1");
                    //    });

                    c.OperationFilter<MoovShackTokenHeaderParameter>();
                })
                .EnableSwaggerUi(c =>
                {

                    // If your API has multiple versions and you've applied the MultipleApiVersions setting
                    // as described above, you can also enable a select box in the swagger-ui, that displays
                    // a discovery URL for each version. This provides a convenient way for users to browse documentation
                    // for different API versions.
                    //
                    //c.EnableDiscoveryUrlSelector();

                });

You can see that so far MultipleApiVersions are disabled - from one good reason as it doesn't produce any results.您可以看到到目前为止 MultipleApiVersions 被禁用 - 有一个很好的理由,因为它不会产生任何结果。 Especially since I am not sure what " ResolveVersionSupportByRouteConstraint " should do.特别是因为我不确定“ ResolveVersionSupportByRouteConstraint ”应该做什么。

I also read that " EnableDiscoveryUrlSelector " has some kind of impact but I am also not sure if that applies to my case.我还读到“ EnableDiscoveryUrlSelector ”有某种影响,但我也不确定这是否适用于我的情况。 When I enabled it, nothing happened.当我启用它时,什么也没发生。

We use it like this in our project and swagger recognizes it and it looks fine我们在我们的项目中像这样使用它并且swagger识别它并且它看起来很好

[ApiVersion( "1.0" )]
[Route("api/v{version:apiVersion}/[controller]")]  
public class SomeControlelr: Controller{
    [HttpGet("", Name = "Someaction"), MapToApiVersion("1.0")]
    public async Task<IActionResult> SomeAction(string someParameter)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Microsoft.AspNet.WebApi.Versioning进行Web API 2版本控制 - Web API 2 versioning with Microsoft.AspNet.WebApi.Versioning Swagger UI 中的 API 版本控制 - API versioning in Swagger UI 带有醒目的版本控制的Web API,未找到ResolveVersionSupportByRouteConstraint - web api with swagger versioning, ResolveVersionSupportByRouteConstraint not found microsoft/aspnet-api-versioning - 不区分大小写的 URI 端点 - microsoft/aspnet-api-versioning - case-insensitive URI endpoints 使用aspnet-api-versioning时,MVC核心覆盖路由中断Url.RouteUrl帮助器方法 - MVC Core overriding routing breaks Url.RouteUrl helper method when using aspnet-api-versioning Web API版本控制URL - Web API versioning URL 使用URL在Web Api 2中进行控制器版本控制 - Controller Versioning in Web Api 2 using URL 使用属性路由的Web API 2版本控制 - web api 2 versioning using attribute routing 是否可以使用基于目录的版本(webapi / C#)使用swagger / Swashbuckle进行版本控制? - Is it possible to do versioning with swagger/Swashbuckle using directory based version (webapi /C#)? 使用api版本控制的Autofac和swagger给出了例外 - Autofac and swagger with api versioning gives exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM