问题描述
我有一个Spring Boot应用程序,可以从2个规范文件生成2个API。通过添加
,我可以为其中之一生成一个swagger-ui
页面
springdoc.swagger-ui.url=/firstAPI.yaml
到application.properties
。但是如何包含第二个API?
我尝试过:
springdoc.swagger-ui.urls=/firstAPI.yaml,/secondAPI.yaml
尽管可以在顶部栏中的两个规范之间进行选择,但创建了一个http://localhost:8080/v3/api-docs/
但在http://localhost:8080/v3/api-docs/
处的组合,页面上为两者都显示“无法加载API定义”。
解决方法
您可以使用属性urls
:
springdoc.swagger-ui.urls[0].name = first
springdoc.swagger-ui.urls[0].url = /firstAPI.yaml
springdoc.swagger-ui.urls[1].name = second
springdoc.swagger-ui.urls[1].url = /secondAPI.yaml
您可以在documentation中找到此属性。这个问题还有一个不错的FAQ:
springdoc.swagger-ui.urls。*属性适合配置外部(/ v3 / api-docs url)。例如,如果您想在一个应用程序中整合其他服务的所有端点。不要忘记也需要启用CORS。