springfox.documentation.swagger.web.SwaggerResource Java Examples
The following examples show how to use
springfox.documentation.swagger.web.SwaggerResource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GatewaySwaggerProvider.java From smaker with GNU Lesser General Public License v3.0 | 6 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = new ArrayList<>(); List<String> routeHosts = new ArrayList<>(); // 由于我的网关采用的是负载均衡的方式,因此我需要拿到所有应用的serviceId // 获取所有可用的host:serviceId routeLocator.getRoutes().filter(route -> route.getUri().getHost() != null) .filter(route -> !self.equals(route.getUri().getHost())) .subscribe(route -> routeHosts.add(route.getUri().getHost())); // 记录已经添加过的server,存在同一个应用注册了多个服务在nacos上 Set<String> dealed = new HashSet<>(); routeHosts.forEach(instance -> { // 拼接url,样式为/serviceId/v2/api-info,当网关调用这个接口时,会自动通过负载均衡寻找对应的主机 String url = "/" + instance + SWAGGER2URL; if (!dealed.contains(url)) { dealed.add(url); SwaggerResource swaggerResource = new SwaggerResource(); swaggerResource.setUrl(url); swaggerResource.setName(instance); resources.add(swaggerResource); } }); return resources; }
Example #2
Source File: SwaggerProvider.java From microservices-platform with Apache License 2.0 | 6 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = new ArrayList<>(); Set<String> routes = new HashSet<>(); //取出Spring Cloud Gateway中的route routeLocator.getRoutes().subscribe(route -> routes.add(route.getId())); //结合application.yml中的路由配置,只获取有效的route节点 gatewayProperties.getRoutes().stream().filter( routeDefinition -> ( routes.contains(routeDefinition.getId()) && swaggerAggProperties.isShow(routeDefinition.getId()) ) ).forEach(routeDefinition -> routeDefinition.getPredicates().stream() .filter(predicateDefinition -> ("Path").equalsIgnoreCase(predicateDefinition.getName())) .forEach(predicateDefinition -> resources.add( swaggerResource( routeDefinition.getId(), predicateDefinition.getArgs().get(NameUtils.GENERATED_NAME_PREFIX + "0").replace("/**", swaggerAggProperties.getApiDocsPath()) ) ) ) ); return resources; }
Example #3
Source File: SwaggerProvider.java From open-cloud with MIT License | 6 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = new ArrayList<>(); //结合配置的route-路径(Path),和route过滤,只获取有效的route节点 routeDefinitionLocator.getRouteDefinitions() .filter(routeDefinition -> routeDefinition.getUri().toString().contains("lb://")) .subscribe(routeDefinition -> { routeDefinition.getPredicates().stream() .filter(predicateDefinition -> ("Path").equalsIgnoreCase(predicateDefinition.getName())) .filter(predicateDefinition -> !predicateDefinition.getArgs().containsKey("_rateLimit")) .forEach(predicateDefinition -> resources.add(swaggerResource(predicateDefinition.getArgs().get("name"), predicateDefinition.getArgs().get("pattern") .replace("/**", API_URI)))); } ); return resources; }
Example #4
Source File: GatewaySwaggerResourcesProvider.java From e-commerce-microservice with Apache License 2.0 | 5 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = new ArrayList<>(); //Add the default swagger resource that correspond to the gateway's own swagger doc resources.add(swaggerResource("default", "/v2/api-docs")); //Add the registered microservices swagger docs as additional swagger resources List<Route> routes = routeLocator.getRoutes(); routes.forEach(route -> { resources.add(swaggerResource(route.getId(), route.getFullPath().replace("**", "v2/api-docs"))); }); return resources; }
Example #5
Source File: GatewaySwaggerResourcesProvider.java From tutorials with MIT License | 5 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = new ArrayList<>(); //Add the default swagger resource that correspond to the gateway's own swagger doc resources.add(swaggerResource("default", "/v2/api-docs")); //Add the registered microservices swagger docs as additional swagger resources List<Route> routes = routeLocator.getRoutes(); routes.forEach(route -> { resources.add(swaggerResource(route.getId(), route.getFullPath().replace("**", "v2/api-docs"))); }); return resources; }
Example #6
Source File: SwaggerResourceConfig.java From zuihou-admin-cloud with Apache License 2.0 | 5 votes |
/** * 每次访问 http://localhost:8670/api/gate/doc.html 会调用该方法 * * @return */ @Override public List<SwaggerResource> get() { String url = "/swagger-resources"; //获取所有router List<SwaggerResource> resources = new ArrayList<>(); List<Route> routes = routeLocator.getRoutes(); log.info("Route Size:{}", routes.size()); Set<String> services = new HashSet<>(); for (Route route : routes) { if (services.contains(route.getLocation())) { continue; } try { // 通过 restTemplate 远程调用各个服务的 /swagger-resources 地址。获取各个服务的swagger配置 // 访问地址: http://zuihou-test-server/swagger-resources (其中 zuihou-test-server 必须是服务的注册到nacos中的名称,否则无法调用成功 ) JSONArray list = restTemplate.getForObject("http://" + route.getLocation() + url, JSONArray.class); if (!list.isEmpty()) { for (int i = 0; i < list.size(); i++) { SwaggerResource sr = list.getObject(i, SwaggerResource.class); resources.add(swaggerResource(route.getId() + "-" + sr.getName(), contextPath + route.getPrefix() + sr.getUrl())); } } services.add(route.getLocation()); } catch (Exception e) { log.info(route.getLocation() + "服务尚未启动,无法获取swagger信息"); } } if (swaggerProperties != null) { resources.add(swaggerResource(swaggerProperties.getTitle(), "/v2/api-docs?group=" + swaggerProperties.getTitle())); } return resources; }
Example #7
Source File: SwaggerResourceConfig.java From zuihou-admin-cloud with Apache License 2.0 | 5 votes |
@Override public List<SwaggerResource> get() { String url = "/swagger-resources"; //获取所有router List<SwaggerResource> resources = new ArrayList<>(); List<String> routes = new ArrayList<>(); routeLocator.getRoutes().subscribe(route -> routes.add(route.getId())); gatewayProperties.getRoutes().stream() .filter(routeDefinition -> routes.contains(routeDefinition.getId())) .forEach(route -> { route.getPredicates().stream() .filter(predicateDefinition -> ("Path").equalsIgnoreCase(predicateDefinition.getName())) .forEach(predicateDefinition -> { try { JSONArray list = restTemplate.getForObject("http://" + route.getUri().getHost() + url, JSONArray.class); if (!list.isEmpty()) { for (int i = 0; i < list.size(); i++) { SwaggerResource sr = list.getObject(i, SwaggerResource.class); resources.add(swaggerResource(route.getId() + "-" + sr.getName(), "/" + route.getId() + sr.getUrl())); // resources.add(swaggerResource(route.getId() + "-" + sr.getName(), contextPath + "/" + route.getId() + sr.getUrl())); } } } catch (Exception e) { log.warn("加载后端资源时失败{}", route.getUri().getHost()); } } ); }); //gateway 网关和bootsway // resources.add(swaggerResource("网关模块", "/v2/api-docs?group=网关模块")); return resources; }
Example #8
Source File: SwaggerUIConfiguration.java From microservice-patterns with Apache License 2.0 | 5 votes |
@Primary @Bean @Lazy public SwaggerResourcesProvider swaggerResourcesProvider(InMemorySwaggerResourcesProvider defaultResourcesProvider, RestTemplate temp) { return () -> { List<SwaggerResource> resources = new ArrayList<>(defaultResourcesProvider.get()); resources.clear(); resources.addAll(definitionContext.getSwaggerDefinitions()); return resources; }; }
Example #9
Source File: ServiceDefinitionsContext.java From microservice-patterns with Apache License 2.0 | 5 votes |
public List<SwaggerResource> getSwaggerDefinitions(){ return serviceDescriptions.entrySet().stream().map( serviceDefinition -> { SwaggerResource resource = new SwaggerResource(); resource.setLocation("/service/"+serviceDefinition.getKey()); resource.setName(serviceDefinition.getKey()); resource.setSwaggerVersion("2.0"); return resource; }).collect(Collectors.toList()); }
Example #10
Source File: GatewaySwaggerResourcesProvider.java From jhipster-microservices-example with Apache License 2.0 | 5 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = new ArrayList<>(); //Add the default swagger resource that correspond to the gateway's own swagger doc resources.add(swaggerResource("default", "/v2/api-docs")); //Add the registered microservices swagger docs as additional swagger resources List<Route> routes = routeLocator.getRoutes(); routes.forEach(route -> { resources.add(swaggerResource(route.getId(), route.getFullPath().replace("**", "v2/api-docs"))); }); return resources; }
Example #11
Source File: SwaggerDocumentationConfiguration.java From microservices-basics-spring-boot with Apache License 2.0 | 5 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = new ArrayList<>(); resources.add(this.createSwaggerResource("auth-server", "/userauth/v2/api-docs", "2.0")); resources.add(this.createSwaggerResource("task-service", "/task-service/v2/api-docs", "2.0")); resources.add(this.createSwaggerResource("user-service", "/user-service/v2/api-docs", "2.0")); return resources; }
Example #12
Source File: SwaggerProvider.java From SpringCloud with Apache License 2.0 | 5 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = new ArrayList<>(); routeService.getRouteDefinitions().stream() .forEach(routeDefinition -> routeDefinition.getPredicates().stream() .filter(predicateDefinition -> "Path".equalsIgnoreCase(predicateDefinition.getName())) .peek(predicateDefinition -> log.debug("路由配置参数:{}", predicateDefinition.getArgs())) .forEach(predicateDefinition -> resources.add(swaggerResource(routeDefinition.getId(), predicateDefinition.getArgs().get("pattern").replace("/**", API_URI))))); log.debug("resources:{}", resources); return resources; }
Example #13
Source File: DocumentationConfig.java From SuperBoot with MIT License | 5 votes |
@Override public List<SwaggerResource> get() { List resources = new ArrayList<>(); resources.add(swaggerResource("公共服务", "/v2/api-docs", "1.0-SNAPSHOT")); resources.add(swaggerResource("用户中心", "/UserApi/v2/api-docs", "1.0-SNAPSHOT")); return resources; }
Example #14
Source File: ServiceDefinitionsContext.java From careconnect-reference-implementation with Apache License 2.0 | 5 votes |
public List<SwaggerResource> getSwaggerDefinitions() { List<SwaggerResource> resources = new ArrayList<>(); SwaggerResource resource = new SwaggerResource(); resource.setLocation("/apidocs" ); resource.setName(HapiProperties.getServerName()); resource.setSwaggerVersion("2.0"); resources.add(resource); return resources; }
Example #15
Source File: SwaggerUIConfig.java From careconnect-reference-implementation with Apache License 2.0 | 5 votes |
@Primary @Bean @Lazy public SwaggerResourcesProvider swaggerResourcesProvider(ServiceDefinitionsContext definitionContext ) { return () -> { List<SwaggerResource> resources = new ArrayList<>(); resources.clear(); resources.addAll(definitionContext.getSwaggerDefinitions()); return resources; }; }
Example #16
Source File: SpringTimeSwaggerProvider.java From springtime with Apache License 2.0 | 5 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = super.get(); SwaggerResource springTimeResource = new SwaggerResource(); springTimeResource.setName("SpringTime"); springTimeResource.setLocation("/v2/rfc-api-docs"); resources.add(0, springTimeResource); return resources; }
Example #17
Source File: GatewaySwaggerResourcesProvider.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 5 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = new ArrayList<>(); //Add the default swagger resource that correspond to the gateway's own swagger doc resources.add(swaggerResource("default", "/v2/api-docs")); //Add the registered microservices swagger docs as additional swagger resources List<Route> routes = routeLocator.getRoutes(); routes.forEach(route -> { resources.add(swaggerResource(route.getId(), route.getFullPath().replace("**", "v2/api-docs"))); }); return resources; }
Example #18
Source File: _GatewaySwaggerResourcesProvider.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 5 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = new ArrayList<>(); //Add the default swagger resource that correspond to the gateway's own swagger doc resources.add(swaggerResource("default", "/v2/api-docs")); //Add the registered microservices swagger docs as additional swagger resources List<Route> routes = routeLocator.getRoutes(); routes.forEach(route -> { resources.add(swaggerResource(route.getId(), route.getFullPath().replace("**", "v2/api-docs"))); }); return resources; }
Example #19
Source File: RegistrySwaggerResourcesProvider.java From jhipster-registry with Apache License 2.0 | 5 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = new ArrayList<>(); //Add the registry swagger resource that correspond to the jhipster-registry's own swagger doc resources.add(swaggerResource("jhipster-registry", "/v2/api-docs")); //Add the registered microservices swagger docs as additional swagger resources List<Route> routes = routeLocator.getRoutes(); routes.forEach(route -> { resources.add(swaggerResource(route.getId(), route.getFullPath().replace("**", "v2/api-docs"))); }); return resources; }
Example #20
Source File: SwaggerProvider.java From hasor with Apache License 2.0 | 5 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = new ArrayList<>(); resources.add(swaggerResource("应用接口", "/v2/api-docs", "1.0")); resources.add(swaggerResource("Dataway接口", "/interface-ui/api/docs/swagger2.json", "1.0")); return resources; }
Example #21
Source File: CombinedSwaggerResourcesProvider.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public List<SwaggerResource> get() { SwaggerResource jerseySwaggerResource = new SwaggerResource(); jerseySwaggerResource.setLocation(RedbeamsApi.API_ROOT_CONTEXT + "/swagger.json"); jerseySwaggerResource.setSwaggerVersion("2.0"); jerseySwaggerResource.setName("Redbeams API"); return Stream.concat(Stream.of(jerseySwaggerResource), inMemorySwaggerResourcesProvider.get().stream()).collect(Collectors.toList()); }
Example #22
Source File: CombinedSwaggerResourcesProvider.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public List<SwaggerResource> get() { SwaggerResource jerseySwaggerResource = new SwaggerResource(); jerseySwaggerResource.setLocation(SdxApi.API_ROOT_CONTEXT + "/swagger.json"); jerseySwaggerResource.setSwaggerVersion("2.0"); jerseySwaggerResource.setName("Datalake API"); return Stream.concat(Stream.of(jerseySwaggerResource), inMemorySwaggerResourcesProvider.get().stream()).collect(Collectors.toList()); }
Example #23
Source File: CombinedSwaggerResourcesProvider.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public List<SwaggerResource> get() { SwaggerResource jerseySwaggerResource = new SwaggerResource(); jerseySwaggerResource.setLocation(FreeIpaApi.API_ROOT_CONTEXT + "/swagger.json"); jerseySwaggerResource.setSwaggerVersion("2.0"); jerseySwaggerResource.setName("FreeIPA API"); return Stream.concat(Stream.of(jerseySwaggerResource), inMemorySwaggerResourcesProvider.get().stream()).collect(Collectors.toList()); }
Example #24
Source File: CombinedSwaggerResourcesProvider.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public List<SwaggerResource> get() { SwaggerResource jerseySwaggerResource = new SwaggerResource(); jerseySwaggerResource.setLocation(EnvironmentApi.API_ROOT_CONTEXT + "/swagger.json"); jerseySwaggerResource.setSwaggerVersion("2.0"); jerseySwaggerResource.setName("Environment API"); return Stream.concat(Stream.of(jerseySwaggerResource), inMemorySwaggerResourcesProvider.get().stream()).collect(Collectors.toList()); }
Example #25
Source File: CombinedSwaggerResourcesProvider.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public List<SwaggerResource> get() { SwaggerResource jerseySwaggerResource = new SwaggerResource(); jerseySwaggerResource.setLocation(CoreApi.API_ROOT_CONTEXT + "/swagger.json"); jerseySwaggerResource.setSwaggerVersion("2.0"); jerseySwaggerResource.setName("Auto-scaling API"); return Stream.concat(Stream.of(jerseySwaggerResource), inMemorySwaggerResourcesProvider.get().stream()).collect(Collectors.toList()); }
Example #26
Source File: CombinedSwaggerResourcesProvider.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public List<SwaggerResource> get() { SwaggerResource jerseySwaggerResource = new SwaggerResource(); jerseySwaggerResource.setLocation(CoreApi.API_ROOT_CONTEXT + "/swagger.json"); jerseySwaggerResource.setSwaggerVersion("2.0"); jerseySwaggerResource.setName("Cloudbreak API"); return Stream.concat(Stream.of(jerseySwaggerResource), inMemorySwaggerResourcesProvider.get().stream()).collect(Collectors.toList()); }
Example #27
Source File: GatewaySwaggerResourcesProvider.java From tutorials with MIT License | 5 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = new ArrayList<>(); //Add the default swagger resource that correspond to the gateway's own swagger doc resources.add(swaggerResource("default", "/v2/api-docs")); //Add the registered microservices swagger docs as additional swagger resources List<Route> routes = routeLocator.getRoutes(); routes.forEach(route -> { resources.add(swaggerResource(route.getId(), route.getFullPath().replace("**", "v2/api-docs"))); }); return resources; }
Example #28
Source File: DocumentationConfig.java From halo-docs with Apache License 2.0 | 5 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = new ArrayList<SwaggerResource>(); List<Route> routes = routeLocator.getRoutes(); //在这里遍历的时候,可以排除掉敏感微服务的路由 routes.forEach(route -> resources.add(swaggerResource(route.getId(), route.getFullPath().replace("**", "v2/api-docs"),"2.0"))); return resources; }
Example #29
Source File: SwaggerProvider.java From black-shop with Apache License 2.0 | 5 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = new ArrayList<>(); List<String> routes = new ArrayList<>(); routeLocator.getRoutes().subscribe(route -> routes.add(route.getId())); gatewayProperties.getRoutes().stream().filter(routeDefinition -> routes.contains(routeDefinition.getId())).forEach(route -> { route.getPredicates().stream() .filter(predicateDefinition -> ("Path").equalsIgnoreCase(predicateDefinition.getName())) .forEach(predicateDefinition -> resources.add(swaggerResource(route.getId(), predicateDefinition.getArgs().get(NameUtils.GENERATED_NAME_PREFIX + "0") .replace("**", "v2/api-docs")))); }); return resources; }
Example #30
Source File: GatewaySwaggerProvider.java From open-capacity-platform with Apache License 2.0 | 5 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = new ArrayList<>(); List<String> routes = new ArrayList<>(); //取出Spring Cloud Gateway中的route routeLocator.getRoutes().subscribe(route -> routes.add(route.getId())); //结合application.yml中的路由配置,只获取有效的route节点 gatewayProperties.getRoutes().stream().filter(routeDefinition -> routes.contains(routeDefinition.getId())) .forEach(routeDefinition -> routeDefinition.getPredicates().stream() .filter(predicateDefinition -> ("Path").equalsIgnoreCase(predicateDefinition.getName())) .forEach(predicateDefinition -> resources.add(swaggerResource(routeDefinition.getId(), predicateDefinition.getArgs().get(NameUtils.GENERATED_NAME_PREFIX + "0") .replace("/**", API_URI))))); return resources; }