如何配置springdoc-openapi-starter-webmvc-ui使用自定义fake_api.yml
解决Swagger UI加载自定义YAML文件的配置方案
1. 修改application.properties配置
关闭springdoc自动生成API文档的功能,同时指定Swagger UI加载自定义文件的路径:
springdoc.api-docs.enabled=false springdoc.swagger-ui.url=/fake_api.yml
springdoc.api-docs.enabled=false:禁用自动生成的API文档,避免它覆盖你放在static目录下的自定义yaml文件springdoc.swagger-ui.url=/fake_api.yml:明确指定Swagger UI要加载的自定义API文件路径
2. 确认自定义文件的可访问性
确保fake_api.yml放在src/main/resources/static目录下,启动应用后直接访问http://localhost:8080/fake_api.yml,应该能看到你手写的yaml原始内容,而非自动生成的JSON响应。
3. 验证配置效果
重启应用后打开http://localhost:8080/swagger-ui/index.html,Swagger UI将加载你自定义的API文档,不再显示"No operations defined in spec!"提示。
内容的提问来源于stack exchange,提问作者Chris Curvey
相关产品推荐
相关产品推荐

