No API definition provided(Springdoc2.6+JDK21+Springboot3.2.1+spring6.1.2)

ⅠBackground

my project is a web application,and according to OpenAPI 3 Library for spring-boot
add dependency in <pom.xml>:

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    <version>2.6.0</version>
</dependency>

Ⅱ Problem

springdoc is correct,but swagger-ui does not show any api ,and with hints:No API definition provided

Ⅲ Cause

after several config trials and search on sites, I haven't got answers, and there're too many obsolete topics about swagger2

but luckly,I found that, the resource:/swagger-ui/swagger-initializer.js differs from default swagger demo,and the parameter "url" in js file is empty.

so, I decided to debug ,and finally found the render order of swagger-initializer.js,

here are the code block

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

then it will be replaced with "StringUtils.EMPTY"

meanwhile, if set springdoc.swagger-ui.url=/v3/api-docs.yaml

when it comes to the function "setConfiguredApiDocsUrl",the  "Constants.SWAGGER_UI_DEFAULT_URL" has already been replced ,so it will not work

Ⅳ Solution

so,we should use config in <application.properties>as follows,and finnally it works

#To configure, the path of a custom OpenAPI file . Will be ignored if urls is used. | default:/v3/api-docs/swagger-config
# if want it works, must with springdoc.swagger-ui.disable-swagger-default-url=false
springdoc.swagger-ui.url=/v3/api-docs.yaml
# To disable the swagger-ui default petstore url. (Available since v1.4.1)
springdoc.swagger-ui.disable-swagger-default-url=false
#To disable the springdoc-openapi endpoint (/v3/api-docs by default).
springdoc.api-docs.enabled=true

  • 26
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值