未提供 API 定义 Swagger 无法显示文档

Kév*_*vin 6 spring swagger swagger-ui spring-boot

我无法在 swagger-ui 中显示我的 spring 文档。这是我的配置:

springdoc:
  # api-docs:
    # enabled: true
    # path: /v3/api-docs/swagger-config
  swagger-ui:
    # path: /swagger-ui.html
    disable-swagger-default-url: true
    # config-url: /v3/api-docs/swagger-config
    # url: /v3/api-docs
Run Code Online (Sandbox Code Playgroud)

我输入此 URL 来访问该界面:http://localhost:8080/swagger-ui.html

swagger ui 空

问题是它没有显示从以下位置加载的 api-docs:

“http://localhost:8080/v3/api-docs/swagger-config”

状态:200。

但如果我在网址字段中输入此内容,它就会起作用..我的目标不是每次都输入此内容..

swagger ui 工作

我测试了所有可能的东西..我不明白为什么它不起作用

编辑:招摇配置

{"configUrl":"/v3/api-docs/swagger-config","oauth2RedirectUrl":"http://localhost:8080/swagger-ui/oauth2-redirect.html","url":"/v3/api-docs","validatorUrl":""}{"configUrl":"/v3/api-docs/swagger-config","oauth2RedirectUrl":"http://localhost:8080/swagger-ui/oauth2-redirect.html","url":"/v3/api-docs","validatorUrl":""}
Run Code Online (Sandbox Code Playgroud)

网络选项卡

小智 6

我遇到了类似的问题,并且能够通过更新 springdoc 演示项目“springdoc-openapi-spring-boot-2-webmvc”中的配置来重现它。我定义了以下属性:

springdoc.api-docs.path=/test/v3/api-docs
sprindoc.swagger-ui.config-url=/test/v3/api-docs/swagger-config
springdoc.swagger-ui.path=/test/swagger-ui.html
Run Code Online (Sandbox Code Playgroud)

通过该配置,我能够重现OP报告的问题。对我来说解决这个问题的是添加一个额外的属性:

springdoc.swagger-ui.url=/test/v3/api-docs
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助。