【问题标题】:petstore URL not disabled in SpringDoc OpenAPi在 SpringDoc OpenAPi 中未禁用 petstore URL
【发布时间】:2020-11-18 23:42:18
【问题描述】:

我正在使用SpringDoc 1.4.3 招摇。
我添加了以下配置以禁用application.yml 中的petstore URL

配置

springdoc:
  swagger-ui:
    disable-swagger-default-url: true
    tags-sorter: alpha
    operations-sorter: alpha
    doc-expansion: none

但是当我在探索文本框中点击https://petstore.swagger.io/v2/swagger.json 时,它仍然向我显示petsore URL,如下图所示。

大张旗鼓的图片

【问题讨论】:

    标签: swagger-ui openapi springdoc springdoc-openapi-ui springdoc-ui


    【解决方案1】:

    得益于以下功能支持,已经过测试和验证:

    只需使用以下属性:

    springdoc.swagger-ui.disable-swagger-default-url=true
    

    【讨论】:

    • 仍然有效,但如果我们在探索文本框中显式添加 URL https://petstore.swagger.io/v2/swagger.json ,那么它仍然会显示。如所附屏幕截图所示
    • 如果您想阻止访问,您应该在防火墙规则中阻止它。 Petstore URL 与任何其他 URL 一样。
    【解决方案2】:

    如果建议的属性设置不起作用,请清除浏览器缓存并重新加载 URL。属性设置有效。浪费了 2 个小时才弄明白。

    springdoc:
      swagger-ui:
        disable-swagger-default-url: true
    

    【讨论】:

      【解决方案3】:

      我解决这个问题的唯一方法是添加一个 SwaggerConfig page [tutorial here] 并更改为 OAS_3 并保存,然后您可以将其更改为其他内容。

      return new Docket(DocumentationType.OAS_30)
      

      似乎 Swagger 保留了缓存或其他东西,但保存配置的 OAS_3 似乎让 Swagger 知道停止使用默认值。

      【讨论】:

      • 问题是关于 Springdoc,而这个答案是关于 Springfox。
      【解决方案4】:

      设置下面的属性,这将禁用 Swagger OpenApi 3 UI 模块

      springdoc.api-docs.enabled=false
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-10-02
        • 2021-10-17
        • 1970-01-01
        • 2020-09-24
        • 2020-06-28
        • 2020-10-22
        • 2022-12-08
        • 2021-11-09
        相关资源
        最近更新 更多