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

Swagger UI是一款RESTFUL接口的文档在线自动生成 功能测试功能软件。       现在多数的项目开发中,网站和移动端都需要进行数据交互和对接,这少不了使用REST编写API接口这种场景。例如有些团队,移动端交由了另一团队开发,不同开发小组之间就需要以规范和文档作为标准和协作基础。良好的文档可以让开发事半功倍,而作为又懒又要效率又能交代的码农,当然最希望一 切自动化,或用小聪明来找到最适合的工具。       Swagger-UI简单而一目了然。它能够纯碎的基于html javascript实现,只要稍微整合一下便能成为方便的API在线测试工具。       项目的设计架构中一直提倡使用TDD(测试驱动)原则来开发,swagger-ui在这方面更是能提供很大帮助。 Swagger-UI更倾向于在线测试接口和数据,但其核心是一个javascript插件,只要稍作修改,便能按需求定制出不同格式的说明文档,在github上更是基于它集成到各种语言环境,分支众多。        其官方提供了一个离线版本,它的使用方法十分简单:直接在js格式的资源文件中录入REST API的json信息,便能容易地生成不同模块下的API列表,每个API接口描述和参数、请求方法都能在每个json数组中定制。下面是目前项目中使用到的部分预览图:  Swagger-UI 的官方地址: http://swagger.wordnik.com Github上的项目地址: https://github.com/wordnik/swagger-ui 官方提供的demo地址 http://petstore.swagger.wordnik.com/ 标签:api
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值