【问题标题】:Petstore url ( swagger default app ) not disabled in Springdoc在 Springdoc 中未禁用 Petstore url(swagger 默认应用程序)
【发布时间】:2021-05-23 22:30:52
【问题描述】:

我仍然有“禁用”问题...

我的swagger界面url配置为/swagger-ui.html (它重定向到 /swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config =>这是正常的!) 但是默认的 swagger url ( PetStore ) 仍然可以通过 /swagger-ui/index.html 访问(所以通过从 "?" 中删除所有内容)。

我必须解决这个问题,因为它被视为一个安全问题......

有 4 种方法来配置它,但我使用了 swagger-ui yaml 文件: https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/

我的 application.yaml :


    springdoc:
      swagger-ui:
        path: '/swagger-ui.html'
        configUrl: '/v3/api-docs/swagger-config'
        disable-swagger-default-url: true

但这不会禁用宠物商店。我不知道为什么:-(

我正在使用 springdoc openapi 1.5.7(在 build.gradle 中):

    implementation('org.springdoc:springdoc-openapi-ui:1.5.7') {
        exclude group: 'javax.validation', module: 'validation-api'
    }

我在配置中将路径从“/swagger-ui.html”更改为路径:“/swagger_ui.html”(并再次运行应用程序)此更改有效,所以我不明白为什么它不禁用默认招摇网址。

我在 stackoverflow 上阅读了很多主题,我知道所写的内容,我在需要“配置”的文件(application.properties 或 application.yaml)中得到了答案

【问题讨论】:

  • 如果这对你有帮助stackoverflow.com/q/63152653/3493829
  • 非常感谢!!该主题本身没有给出解决方案,我去了给定的链接,但有人给出了一个带有 swagger-ui 配置的链接,我不知道但它有效!非常感谢!

标签: java swagger openapi springdoc


【解决方案1】:

我终于解决了这个问题,感谢SSK!

这个问题的解决方法,是添加“application.yaml”(在你的文件夹“resources”下的“main”):

springdoc:
  swagger-ui:
    path: /swagger-ui.html
    display-request-duration: true
    groups-order: DESC
    operationsSorter: method
    disable-swagger-default-url: true

我的招摇 http://localhost:8080/swagger-ui.html 非常适合我的应用程序, 你被重定向到 http://localhost:8080/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config 哪个是正确的(并且总是完美地工作)!

但是在尝试使用这些网址时: http://localhost:8080/swagger-ui/index.html?configUrl= http://localhost:8080/swagger-ui/index.html 它给出了“没有提供 API 定义。”,所以它是完全安全的,并且“demo PetStore”被禁用了!

祝你有美好的一天!

【讨论】:

    【解决方案2】:

    从版本 v1.4.1 开始,以下属性可用于禁用 swagger-ui 默认 petstore url:

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

    这在 springdoc-openapi 的the F.A.Q 中也有回答。

    【讨论】:

    • 感谢您的回答,但我当然在 FAQ 和 stackoverflow 的一些帖子中看到了这一点。但是只有这样它不起作用,我必须完全按照我在下面放置的( application.yaml ),这是它唯一的工作方式。没办法,找了好久。。
    猜你喜欢
    • 2020-11-18
    • 1970-01-01
    • 2021-06-23
    • 1970-01-01
    • 1970-01-01
    • 2021-09-19
    • 2020-07-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多