Commit e8e0e306 by Nepxion

增加Swagger接口

parent 3635799e
......@@ -19,5 +19,15 @@
<groupId>${project.groupId}</groupId>
<artifactId>discovery-plugin-framework</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -12,12 +12,14 @@ package com.nepxion.discovery.plugin.routercenter.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.client.RestTemplate;
import com.nepxion.discovery.plugin.routercenter.controller.RouterController;
@Configuration
@ComponentScan(basePackages = { "com.nepxion.discovery.plugin.routercenter.controller" })
@Import(SwaggerConfiguration.class)
public class RouterAutoConfiguration {
@Bean
public RestTemplate routerRestTemplate() {
......
......@@ -9,6 +9,10 @@ package com.nepxion.discovery.plugin.routercenter.controller;
* @version 1.0
*/
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -36,6 +40,7 @@ import com.nepxion.discovery.plugin.framework.exception.PluginException;
import com.nepxion.eventbus.util.HostUtil;
@RestController
@Api(tags = { "路由接口" })
public class RouterController {
@Autowired
private PluginContainerInitializedHandler pluginContainerInitializedHandler;
......@@ -52,33 +57,33 @@ public class RouterController {
@Autowired
private DiscoveryClient discoveryClient;
// 获取本地节点可访问其他节点(根据服务名)的实例列表
@RequestMapping(path = "/instances/{serviceId}", method = RequestMethod.GET)
public List<ServiceInstance> instances(@PathVariable(value = "serviceId") String serviceId) {
@ApiOperation(value = "获取本地节点可访问其他节点(根据服务名)的实例列表", notes = "", response = List.class, httpMethod = "GET")
public List<ServiceInstance> instances(@PathVariable(value = "serviceId") @ApiParam(value = "目标服务名", required = true) String serviceId) {
return getInstanceList(serviceId);
}
// 获取本地节点的路由信息(只显示当前节点的简单信息,不包含下级路由)
@RequestMapping(path = "/info", method = RequestMethod.GET)
@ApiOperation(value = "获取本地节点的路由信息", notes = "只显示当前节点的简单信息,不包含下级路由", response = RouterEntity.class, httpMethod = "GET")
public RouterEntity info() {
return getRouterEntity();
}
// 获取本地节点可访问其他节点(根据服务名)的路由信息列表
@RequestMapping(path = "/route/{routeServiceId}", method = RequestMethod.GET)
public List<RouterEntity> route(@PathVariable(value = "routeServiceId") String routeServiceId) {
@ApiOperation(value = "获取本地节点可访问其他节点(根据服务名)的路由信息列表", notes = "", response = List.class, httpMethod = "GET")
public List<RouterEntity> route(@PathVariable(value = "routeServiceId") @ApiParam(value = "目标服务名", required = true) String routeServiceId) {
return getRouterEntityList(routeServiceId);
}
// 获取指定节点(根据IP和端口)可访问其他节点(根据服务名)的路由信息列表
@RequestMapping(path = "/route/{routeServiceId}/{routeHost}/{routePort}", method = RequestMethod.GET)
public List<RouterEntity> route(@PathVariable(value = "routeServiceId") String routeServiceId, @PathVariable(value = "routeHost") String routeHost, @PathVariable(value = "routePort") int routePort) {
@ApiOperation(value = "获取指定节点(根据IP和端口)可访问其他节点(根据服务名)的路由信息列表", notes = "", response = List.class, httpMethod = "GET")
public List<RouterEntity> route(@PathVariable(value = "routeServiceId") @ApiParam(value = "目标服务名", required = true) String routeServiceId, @PathVariable(value = "routeHost") @ApiParam(value = "目标服务所在机器的IP地址", required = true) String routeHost, @PathVariable(value = "routePort") @ApiParam(value = "目标服务所在机器的端口号", required = true) int routePort) {
return getRouterEntityList(routeServiceId, routeHost, routePort);
}
// 获取全路径的路由信息(routeServiceIds按调用服务名的前后次序排列,起始节点的服务名不能加上去。如果多个用“;”分隔,不允许出现空格)
@RequestMapping(path = "/routes", method = RequestMethod.POST)
public RouterEntity routes(@RequestBody String routeServiceIds) {
@ApiOperation(value = "获取全路径的路由信息树", notes = "参数按调用服务名的前后次序排列,起始节点的服务名不能加上去。如果多个用“;”分隔,不允许出现空格", response = RouterEntity.class, httpMethod = "POST")
public RouterEntity routes(@RequestBody @ApiParam(value = "例如:service-a;service-b", required = true) String routeServiceIds) {
return routeTree(routeServiceIds);
}
......
......@@ -31,4 +31,14 @@ spring.application.register.failure.event.enabled=false
# 开启和关闭服务发现层面的控制。一旦关闭,服务多版本调用的控制功能将失效,动态屏蔽指定IP地址的服务实例被发现的功能将失效。缺失则默认为true
spring.application.discovery.control.enabled=true
# 开启和关闭远程配置中心规则文件读取。一旦关闭,默认读取本地规则文件(例如:rule.xml)。缺失则默认为true
spring.application.discovery.remote.config.enabled=true
\ No newline at end of file
spring.application.discovery.remote.config.enabled=true
# Swagger config
swagger.service.base.package=com.nepxion.discovery.plugin.routercenter.controller
swagger.service.description=Router Restful APIs
swagger.service.version=1.0.0
swagger.service.license=Apache License 2.0
swagger.service.license.url=http://www.apache.org/licenses/LICENSE-2.0
swagger.service.contact.name=Haojun Ren
swagger.service.contact.url=https://github.com/Nepxion/Discovery
swagger.service.contact.email=1394997@qq.com
\ No newline at end of file
......@@ -31,8 +31,9 @@
<commons.collections4.version>4.1</commons.collections4.version>
<commons.io.version>2.5</commons.io.version>
<dom4j.version>1.6.1</dom4j.version>
<swagger.version>2.7.0</swagger.version>
<spring.cloud.version>Edgware.SR4</spring.cloud.version>
<!-- <spring.cloud.version>Dalston.SR5</spring.cloud.version> -->
<!-- <spring.cloud.version>Dalston.SR5</spring.cloud.version> -->
<spring.cloud.consul.version>2.0.0.RELEASE</spring.cloud.consul.version>
<spring.cloud.zookeeper.version>2.0.0.RELEASE</spring.cloud.zookeeper.version>
<spring.boot.version>1.5.14.RELEASE</spring.boot.version>
......@@ -135,6 +136,18 @@
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud.version}</version>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment