【问题标题】:How to disable swagger validation in net core如何在网络核心中禁用招摇验证
【发布时间】:2017-12-21 02:21:36
【问题描述】:

我正在寻找一种在将 Swashbuckle 用于 net core web api 项目时禁用 swagger 验证功能的方法。更准确地说,如何将 ValidatorUrl 设置为 null。

【问题讨论】:

标签: asp.net-core swashbuckle


【解决方案1】:

我发现默认情况下它没有被禁用。我正在运行 Swashbuckle.AspNetCore v1.1.0 和 .net core 2.0。我尝试了以下不起作用的方法

app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "MY API");
            c.EnabledValidator(null);
        });

我找到的唯一解决方案是修改他们的 swagger-ui.js 文件。我不喜欢这个解决方案,但它有效。

在第 198 行附近,您将看到以下内容:

    return "    <span style=\"float:right\"><a target=\"_blank\" href=\""
    + ((stack1 = (helpers.escape || (depth0 && depth0.escape) || alias2).call(alias1,(depth0 != null ? depth0.validatorUrl : depth0),{"name":"escape","hash":{},"data":data})) != null ? stack1 : "")
    + "/debug?url="
    + ((stack1 = (helpers.escape || (depth0 && depth0.escape) || alias2).call(alias1,(depth0 != null ? depth0.url : depth0),{"name":"escape","hash":{},"data":data})) != null ? stack1 : "")
    + "\"><img id=\"validator\" src=\""
    + ((stack1 = (helpers.escape || (depth0 && depth0.escape) || alias2).call(alias1,(depth0 != null ? depth0.validatorUrl : depth0),{"name":"escape","hash":{},"data":data})) != null ? stack1 : "")
    + "?url="
    + ((stack1 = (helpers.escape || (depth0 && depth0.escape) || alias2).call(alias1,(depth0 != null ? depth0.url : depth0),{"name":"escape","hash":{},"data":data})) != null ? stack1 : "")
    + "\"></a>\n    </span>\n";
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
    var stack1, alias1=depth0 != null ? depth0 : {};

我删除了他们的锚标签,现在看起来像这样:

  return "    <span style=\"float:right\"></span>\n";
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
    var stack1, alias1=depth0 != null ? depth0 : {};

【讨论】:

    猜你喜欢
    • 2019-03-19
    • 1970-01-01
    • 2020-09-30
    • 2017-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-14
    • 2016-08-30
    相关资源
    最近更新 更多