我仍然遇到“禁用”问题...
我的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/
我的应用程序.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”(并再次运行应用程序)此更改有效,所以我不明白为什么它不禁用默认的 swagger网址。
我阅读了 stackoverflow 上的许多主题,我确切地了解了所写的内容,我在需要“配置”的文件( application.properties 或 application.yaml )中得到了答案
我终于解决了问题,感谢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
我的 swagger 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 定义。”,因此它是完全安全的,并且“演示 PetStore”已被禁用!
祝你有美好的一天!
从 v1.4.1 版本开始,以下属性可用于禁用 swagger-ui 默认 petstore url:
springdoc.swagger-ui.disable-swagger-default-url=true
这在 springdoc-openapi 的 F.A.Q 中也有解答。