|
@@ -0,0 +1,43 @@
|
|
|
+package com.diagbot.config.swagger;
|
|
|
+
|
|
|
+import org.springframework.cloud.netflix.zuul.filters.Route;
|
|
|
+import org.springframework.cloud.netflix.zuul.filters.RouteLocator;
|
|
|
+import org.springframework.context.annotation.Primary;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import springfox.documentation.swagger.web.SwaggerResource;
|
|
|
+import springfox.documentation.swagger.web.SwaggerResourcesProvider;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description: 集中管理swagger
|
|
|
+ * @author: gaodm
|
|
|
+ * @time: 2018/8/22 16:44
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Primary
|
|
|
+public class GatewaySwaggerResourcesProvider implements SwaggerResourcesProvider {
|
|
|
+ private final RouteLocator routeLocator;
|
|
|
+
|
|
|
+ public GatewaySwaggerResourcesProvider(RouteLocator routeLocator) {
|
|
|
+ this.routeLocator = routeLocator;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SwaggerResource> get() {
|
|
|
+ List<SwaggerResource> resources = new ArrayList<>();
|
|
|
+ List<Route> routes = routeLocator.getRoutes();
|
|
|
+ for (Route route:routes) {
|
|
|
+ resources.add(swaggerResource(route.getId(), route.getFullPath().replace("**", "v2/api-docs")));
|
|
|
+ }
|
|
|
+ return resources;
|
|
|
+ }
|
|
|
+ private SwaggerResource swaggerResource(String name, String location) {
|
|
|
+ SwaggerResource swaggerResource = new SwaggerResource();
|
|
|
+ swaggerResource.setName(name);
|
|
|
+ swaggerResource.setLocation(location);
|
|
|
+ swaggerResource.setSwaggerVersion("2.0");
|
|
|
+ return swaggerResource;
|
|
|
+ }
|
|
|
+}
|