Ⅰ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