【问题标题】:How disable the swagger validator when using Swashbuckle for a net core web api project. Swashbuckle 6.0.0将 Swashbuckle 用于 net core web api 项目时如何禁用 swagger 验证器。花花公子 6.0.0
【发布时间】:2017-02-16 19:11:04
【问题描述】:

如何在 Swashbuckle 6.0.0 的选项中禁用 Swagger Schema 验证器。我知道它在本地运行时默认关闭,但没有看到 SwaggerUI() 的 validatorURL 选项

【问题讨论】:

    标签: asp.net-core swagger swashbuckle


    【解决方案1】:

    似乎 Swagger 6.0.0 上的 there is an option 来管理 Validator。

    自己没有尝试过,但似乎对它的作用非常明确。

    【讨论】:

      【解决方案2】:

      来自github repository

      此级别的配置将在即将发布的稳定 6.0.0 版本中提供,如自定义 UI 配置示例网站所示:

      https://github.com/domaindrivendev/Ahoy/blob/master/test/WebSites/CustomUiConfig/Startup.cs#L30

      如果你不能等到那个时候,它也可以通过 MyGet 上的预览包获得

      【讨论】:

        【解决方案3】:

        Swashbuckle 6.0.0 重命名为 Swashbuckle.AspNetCore 1.0.0See here...

        他们还从 DisableValidator (.NET Framework) 切换到 EnableValidator (.NET Core),正如您在 the docu 中看到的那样。因此,Swashbuckle.AspNetCore 1.0.0 中的验证器似乎默认处于禁用状态。

        app.UseSwaggerUI(c =>
        {
            c.EnabledValidator();
            /* ... */
        });
        

        【讨论】:

          【解决方案4】:
          var config = new HttpConfiguration();
          config.EnableSwagger(c =>{ })
                .EnableSwaggerUi(c => { c.DisableValidator(); });   
          

          【讨论】:

          【解决方案5】:

          在 Swashbuckle.AspNetCore 2.0.0 中,您可以通过将 ValidatorUrl 设置为 null 来禁用 Startup.Configure() 方法中的验证:

          app.UseSwaggerUI(c =>
              {
                  c.ValidatorUrl(null);
              });
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2018-07-29
            • 1970-01-01
            • 1970-01-01
            • 2018-03-23
            • 1970-01-01
            相关资源
            最近更新 更多