Springdoc OpenAPI多服务器json



我正在研究是否有可能拥有一个中央swagger UI,您可以在其中从多个localhost查看/v3/api文档。

我的想法是让多个GroupedOpenApiBeans分别连接到不同的本地主机。例如:

@Bean
public GroupedOpenApi apimicroservice() {
String service = discoveryClient.getServices().get(0);
return GroupedOpenApi.builder().group("microservice-test").pathsToMatch(
//Here the api-docs of the given host, example:
"http://localhost:8080/v3/api-docs"
//Or like how I want it with eureka:
"http://" + service + "/v3/api-docs"
).build();
} 

这可能吗,也许不是GroupedOpenApi,而是其他什么?

当我现在为GroupedOpenApi创建多个@Bean时,它可以工作,但我希望它是带有List<GroupedOpenApi>的1个bean,但这在我的UI中不起作用。这可能吗?

提前感谢!

对于集中式swagger ui,您需要在顶部使用类似api网关的抽象来组合响应

参考:https://piotrminkowski.com/2020/02/20/microservices-api-documentation-with-springdoc-openapi/

完全归功于piotr制作了本教程。

最新更新