如何从多个 yaml 规范生成 swagger-ui?

How to generate swagger-ui from several yaml specifications?

我有一个 spring 引导应用程序,它从 2 个规范文件生成 2 APIs。我可以通过添加

为其中之一生成一个 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. There is also a nice FAQ 中找到此问题的 属性:

The properties springdoc.swagger-ui.urls.*, are suitable to configure external (/v3/api-docs url). For example if you want to agreagte all the endpoints of other services, inside one single application. Don’t forget that CORS needs to be enabled as well.