Swashbuckle UI显示不同版本的相同信息

时间:2016-10-28 17:13:13

标签: swagger swagger-ui swagger-2.0 swashbuckle

我们在Web Api项目中实现了Swashbuckle,我注意到SwaggerUI测试工具为地址中指定的任何版本显示完全相同的信息。更具体地说,它显示了SwaggerConfig中VersionInfoBuilder首先出现的swagger信息。

例如,如果我导航到“/ preview / swagger / index” - 显示的UI是与版本'preview'无关的所有v1信息。

我在这里做错了什么?

public class SwaggerConfig
{
    private SwaggerConfig() { }

    public static void Register()
    {
        var thisAssembly = typeof(SwaggerConfig).Assembly;
        GlobalConfiguration.Configuration
            .EnableSwagger("{apiVersion}/swagger", c =>
            {
                c.MultipleApiVersions(
                    (apiDesc, version) =>
                    {
                        var path = apiDesc.RelativePath.Split('/');
                        var pathVersion = path[0];

                        return CultureInfo.InvariantCulture.CompareInfo.IndexOf(pathVersion, version, CompareOptions.IgnoreCase) >= 0;
                    },
                    vc =>
                    {
                        vc.Version("v1", "Api - v1");
                        vc.Version("preview", "Api - Preview");
                    });
            })
            .EnableSwaggerUi("{apiVersion}/swagger/{*assetPath}", c =>
            {
                c.DisableValidator();
            });
    }
}

1 个答案:

答案 0 :(得分:1)

我认为配置不对,只是你的期望不正确。

您不必导航到另一个Swagger UI(var rotation = 0; var rotating = false; var startX = 0; jQuery.fn.rotate = function(degrees) { $(this).css({'transform' : 'rotate('+ degrees +'deg)'}); }; $(document).mousemove(function(e){ if (!rotating) return; rotation = startX - e.clientX; $('.child').rotate(rotation); }); $(document).on("mouseup", function(){ rotating = false; }); $('.rotateButton1').on("mousedown", function(e) { e.stopImmediatePropagation(); rotating = true; startX = e.clientX; }); ),但您必须将Swagger UI指向另一个规范。只需在标题的输入框中输入http://yourserver:yourport/preview/swagger,然后按“浏览”。 Swagger UI现在将加载并显示预览规范。

enter image description here