DocumentationConfig.java
1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.example.geteway;
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;
@Component
@Primary
public class DocumentationConfig implements SwaggerResourcesProvider {
private RouteLocator routeLocator;
public DocumentationConfig(RouteLocator routeLocator){
this.routeLocator = routeLocator;
}
@Override
public List<SwaggerResource> get() {
List resources = new ArrayList();
List<Route> routes = routeLocator.getRoutes();
System.out.println("routes:"+routes.toString());
for (Route route :
routes) {
resources.add(swaggerResource(route.getId(), route.getFullPath().replace("**", "v2/api-docs"), "1.0"));
}
// resources.add(swaggerResource("海康指纹接口","/mygateway/haikangserver/v2/api-docs","1.0"));
// resources.add(swaggerResource("大华人脸接口","","1.0"));
return resources;
}
private SwaggerResource swaggerResource(String name,String location,String version){
SwaggerResource swaggerResource = new SwaggerResource();
swaggerResource.setName(name);
swaggerResource.setLocation(location);
swaggerResource.setSwaggerVersion(version);
return swaggerResource;
}
}