首页 > 解决方案 > 在 Springdoc 中未禁用 Petstore url(swagger 默认应用程序)

问题描述

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

我的招摇界面网址配置为 /swagger-ui.html (它重定向到 /swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config =>这是正常的!)但默认招摇网址( 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 )

标签: javaswaggeropenapispringdoc

解决方案


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

此问题的解决方案是添加“application.yaml”(在“main”下的文件夹“resources”中):

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”被禁用了!

祝你今天过得愉快 !


推荐阅读