Skip to content

Commit

Permalink
Merge pull request zhoutaoo#149 from zhoutaoo/dev
Browse files Browse the repository at this point in the history
Dev To Master
  • Loading branch information
zhoutaoo committed Jun 6, 2020
2 parents 330e7e0 5caf628 commit 0287117
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 33,7 @@ public void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.authorizeRequests()
.antMatchers("/actuator/**").permitAll()
.antMatchers("/v2/api-docs").permitAll()
.anyRequest().authenticated();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 32,15 @@ public Result add(@Valid @RequestBody ProductForm productForm) {
}

@ApiOperation(value = "删除产品", notes = "根据url的id来指定删除对象")
@ApiImplicitParam(paramType = "path", name = "id", value = "产品ID", required = true, dataType = "long")
@ApiImplicitParam(paramType = "path", name = "id", value = "产品ID", required = true, dataType = "string")
@DeleteMapping(value = "/{id}")
public Result delete(@PathVariable String id) {
return Result.success(productService.delete(id));
}

@ApiOperation(value = "修改产品", notes = "修改指定产品信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "产品ID", required = true, dataType = "long"),
@ApiImplicitParam(name = "id", value = "产品ID", required = true, dataType = "string"),
@ApiImplicitParam(name = "productForm", value = "产品实体", required = true, dataType = "ProductForm")
})
@PutMapping(value = "/{id}")
Expand All @@ -51,7 51,7 @@ public Result update(@PathVariable String id, @Valid @RequestBody ProductForm pr
}

@ApiOperation(value = "获取产品", notes = "获取指定产品信息")
@ApiImplicitParam(paramType = "path", name = "id", value = "产品ID", required = true, dataType = "long")
@ApiImplicitParam(paramType = "path", name = "id", value = "产品ID", required = true, dataType = "string")
@GetMapping(value = "/{id}")
public Result get(@PathVariable String id) {
log.info("get with id:{}", id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 33,15 @@ public Result add(@Valid @RequestBody GatewayRouteForm gatewayRoutForm) {
}

@ApiOperation(value = "删除网关路由", notes = "根据url的id来指定删除对象")
@ApiImplicitParam(paramType = "path", name = "id", value = "网关路由ID", required = true, dataType = "long")
@ApiImplicitParam(paramType = "path", name = "id", value = "网关路由ID", required = true, dataType = "string")
@DeleteMapping(value = "/{id}")
public Result delete(@PathVariable String id) {
return Result.success(gatewayRoutService.delete(id));
}

@ApiOperation(value = "修改网关路由", notes = "修改指定网关路由信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "网关路由ID", required = true, dataType = "long"),
@ApiImplicitParam(name = "id", value = "网关路由ID", required = true, dataType = "string"),
@ApiImplicitParam(name = "gatewayRoutForm", value = "网关路由实体", required = true, dataType = "GatewayRouteForm")
})
@PutMapping(value = "/{id}")
Expand All @@ -52,7 52,7 @@ public Result update(@PathVariable String id, @Valid @RequestBody GatewayRouteFo
}

@ApiOperation(value = "获取网关路由", notes = "根据id获取指定网关路由信息")
@ApiImplicitParam(paramType = "path", name = "id", value = "网关路由ID", required = true, dataType = "long")
@ApiImplicitParam(paramType = "path", name = "id", value = "网关路由ID", required = true, dataType = "string")
@GetMapping(value = "/{id}")
public Result get(@PathVariable String id) {
log.info("get with id:{}", id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 17,7 @@
@AllArgsConstructor
@Slf4j
public class SwaggerProvider implements SwaggerResourcesProvider {
private static final String API_URI = "/v2/api-docs";
public static final String API_URI = "/v2/api-docs";

@Autowired
private final RouteService routeService;
Expand All @@ -38,8 38,8 @@ public List<SwaggerResource> get() {
private SwaggerResource swaggerResource(String name, String location) {
SwaggerResource swaggerResource = new SwaggerResource();
swaggerResource.setName(name);
swaggerResource.setLocation(location);
swaggerResource.setSwaggerVersion("2.0");
swaggerResource.setUrl(location);
return swaggerResource;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 1,37 @@
package com.springboot.cloud.gateway.filter;

import com.springboot.cloud.gateway.config.SwaggerProvider;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

//@Component
@Slf4j
public class SwaggerHeaderFilter implements GlobalFilter, Ordered {

private static final String HEADER_NAME = "X-Forwarded-Prefix";

@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
ServerHttpRequest request = exchange.getRequest();
String path = request.getURI().getPath();
if (!StringUtils.endsWithIgnoreCase(path, SwaggerProvider.API_URI)) {
return chain.filter(exchange);
}
String basePath = path.substring(0, path.lastIndexOf(SwaggerProvider.API_URI));
log.info("basePath: {}", basePath);
ServerHttpRequest newRequest = request.mutate().header(HEADER_NAME, basePath).build();
ServerWebExchange newExchange = exchange.mutate().request(newRequest).build();
return chain.filter(newExchange);
}

@Override
public int getOrder() {
return -200;
}
}
6 changes: 1 addition & 5 deletions gateway/gateway-web/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 11,6 @@ spring:
lettuce:
pool:
max-active: 300
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:${DATASOURCE_DBTYPE:mysql}://${DATASOURCE_HOST:localhost}:${DATASOURCE_PORT:3306}/sc_gateway?characterEncoding=UTF-8&useUnicode=true&useSSL=false
username: ${DATASOURCE_USERNAME:root}
password: ${DATASOURCE_PASSWORD:root123}

zipkin:
enabled: true
Expand Down Expand Up @@ -45,6 40,7 @@ spring:
redis-rate-limiter.burstCapacity: 10 #令牌桶的容积
rate-limiter: "#{@defaultRedisRateLimiter}" #SPEL表达式去的对应的bean
key-resolver: "#{@apiKeyResolver}" #SPEL表达式去的对应的bean

feign:
sentinel:
enabled: true
Expand Down
5 changes: 1 addition & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 28,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.4.RELEASE</version>
<version>2.1.10.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -82,9 82,6 @@
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 31,15 @@ public Result add(@Valid @RequestBody GroupForm groupForm) {
}

@ApiOperation(value = "删除用户组", notes = "根据url的id来指定删除对象")
@ApiImplicitParam(paramType = "path", name = "id", value = "用户组ID", required = true, dataType = "long")
@ApiImplicitParam(paramType = "path", name = "id", value = "用户组ID", required = true, dataType = "string")
@DeleteMapping(value = "/{id}")
public Result delete(@PathVariable String id) {
return Result.success(groupService.delete(id));
}

@ApiOperation(value = "修改用户组", notes = "修改指定用户组信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "用户组ID", required = true, dataType = "long"),
@ApiImplicitParam(name = "id", value = "用户组ID", required = true, dataType = "string"),
@ApiImplicitParam(name = "groupForm", value = "用户组实体", required = true, dataType = "GroupForm")
})
@PutMapping(value = "/{id}")
Expand All @@ -50,7 50,7 @@ public Result update(@PathVariable String id, @Valid @RequestBody GroupForm grou
}

@ApiOperation(value = "获取用户组", notes = "获取指定用户组信息")
@ApiImplicitParam(paramType = "path", name = "id", value = "用户组ID", required = true, dataType = "long")
@ApiImplicitParam(paramType = "path", name = "id", value = "用户组ID", required = true, dataType = "string")
@GetMapping(value = "/{id}")
public Result get(@PathVariable String id) {
log.debug("get with id:{}", id);
Expand Down Expand Up @@ -82,7 82,7 @@ public Result search(@Valid @RequestBody GroupQueryForm groupQueryForm) {
}

@ApiOperation(value = "根据父id查询用户组", notes = "根据父id查询用户组列表")
@ApiImplicitParam(paramType = "path", name = "id", value = "用户组父ID", required = true, dataType = "long")
@ApiImplicitParam(paramType = "path", name = "id", value = "用户组父ID", required = true, dataType = "string")
@GetMapping(value = "/parent/{id}")
public Result search(@PathVariable String id) {
log.debug("query with parent id:{}", id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 32,15 @@ public Result add(@Valid @RequestBody MenuForm menuForm) {
}

@ApiOperation(value = "删除菜单", notes = "根据url的id来指定删除对象")
@ApiImplicitParam(paramType = "path", name = "id", value = "菜单ID", required = true, dataType = "long")
@ApiImplicitParam(paramType = "path", name = "id", value = "菜单ID", required = true, dataType = "string")
@DeleteMapping(value = "/{id}")
public Result delete(@PathVariable String id) {
return Result.success(menuService.delete(id));
}

@ApiOperation(value = "修改菜单", notes = "修改指定菜单信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "菜单ID", required = true, dataType = "long"),
@ApiImplicitParam(name = "id", value = "菜单ID", required = true, dataType = "string"),
@ApiImplicitParam(name = "menuForm", value = "菜单实体", required = true, dataType = "MenuForm")
})
@PutMapping(value = "/{id}")
Expand All @@ -51,7 51,7 @@ public Result update(@PathVariable String id, @Valid @RequestBody MenuForm menuF
}

@ApiOperation(value = "获取菜单", notes = "获取指定菜单信息")
@ApiImplicitParam(paramType = "path", name = "id", value = "菜单ID", required = true, dataType = "long")
@ApiImplicitParam(paramType = "path", name = "id", value = "菜单ID", required = true, dataType = "string")
@GetMapping(value = "/{id}")
public Result get(@PathVariable String id) {
log.debug("get with id:{}", id);
Expand Down Expand Up @@ -82,7 82,7 @@ public Result search(@Valid @RequestBody MenuQueryForm menuQueryForm) {
}

@ApiOperation(value = "根据父id查询菜单", notes = "根据父id查询菜单列表")
@ApiImplicitParam(paramType = "path", name = "id", value = "菜单父ID", required = true, dataType = "long")
@ApiImplicitParam(paramType = "path", name = "id", value = "菜单父ID", required = true, dataType = "string")
@GetMapping(value = "/parent/{id}")
public Result search(@PathVariable String id) {
log.debug("query with parent id:{}", id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 31,15 @@ public Result add(@Valid @RequestBody PositionForm positionForm) {
}

@ApiOperation(value = "删除职位", notes = "根据url的id来指定删除对象")
@ApiImplicitParam(paramType = "path", name = "id", value = "职位ID", required = true, dataType = "long")
@ApiImplicitParam(paramType = "path", name = "id", value = "职位ID", required = true, dataType = "string")
@DeleteMapping(value = "/{id}")
public Result delete(@PathVariable String id) {
return Result.success(positionService.delete(id));
}

@ApiOperation(value = "修改职位", notes = "修改指定职位信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "职位ID", required = true, dataType = "long"),
@ApiImplicitParam(name = "id", value = "职位ID", required = true, dataType = "string"),
@ApiImplicitParam(name = "positionForm", value = "职位实体", required = true, dataType = "PositionForm")
})
@PutMapping(value = "/{id}")
Expand All @@ -50,7 50,7 @@ public Result update(@PathVariable String id, @Valid @RequestBody PositionForm p
}

@ApiOperation(value = "获取职位", notes = "获取指定职位信息")
@ApiImplicitParam(paramType = "path", name = "id", value = "职位ID", required = true, dataType = "long")
@ApiImplicitParam(paramType = "path", name = "id", value = "职位ID", required = true, dataType = "string")
@GetMapping(value = "/{id}")
public Result get(@PathVariable String id) {
log.debug("get with id:{}", id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 32,15 @@ public Result add(@Valid @RequestBody ResourceForm resourceForm) {
}

@ApiOperation(value = "删除资源", notes = "根据url的id来指定删除对象")
@ApiImplicitParam(paramType = "path", name = "id", value = "资源ID", required = true, dataType = "long")
@ApiImplicitParam(paramType = "path", name = "id", value = "资源ID", required = true, dataType = "string")
@DeleteMapping(value = "/{id}")
public Result delete(@PathVariable String id) {
return Result.success(resourceService.delete(id));
}

@ApiOperation(value = "修改资源", notes = "修改指定资源信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "资源ID", required = true, dataType = "long"),
@ApiImplicitParam(name = "id", value = "资源ID", required = true, dataType = "string"),
@ApiImplicitParam(name = "resourceForm", value = "资源实体", required = true, dataType = "ResourceForm")
})
@PutMapping(value = "/{id}")
Expand All @@ -50,15 50,15 @@ public Result update(@PathVariable String id, @Valid @RequestBody ResourceForm r
}

@ApiOperation(value = "获取资源", notes = "获取指定资源信息")
@ApiImplicitParam(paramType = "path", name = "id", value = "资源ID", required = true, dataType = "long")
@ApiImplicitParam(paramType = "path", name = "id", value = "资源ID", required = true, dataType = "string")
@GetMapping(value = "/{id}")
public Result get(@PathVariable String id) {
log.debug("get with id:{}", id);
return Result.success(resourceService.get(id));
}

@ApiOperation(value = "查询资源", notes = "根据userId查询用户所拥有的资源信息")
@ApiImplicitParam(paramType = "path", name = "userId", value = "用户id", required = true, dataType = "long")
@ApiImplicitParam(paramType = "path", name = "userId", value = "用户id", required = true, dataType = "string")
@ApiResponses(
@ApiResponse(code = 200, message = "处理成功", response = Result.class)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 33,15 @@ public Result add(@Valid @RequestBody RoleForm roleForm) {
}

@ApiOperation(value = "删除角色", notes = "根据url的id来指定删除对象")
@ApiImplicitParam(paramType = "path", name = "id", value = "角色ID", required = true, dataType = "long")
@ApiImplicitParam(paramType = "path", name = "id", value = "角色ID", required = true, dataType = "string")
@DeleteMapping(value = "/{id}")
public Result delete(@PathVariable String id) {
return Result.success(roleService.delete(id));
}

@ApiOperation(value = "修改角色", notes = "修改指定角色信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "角色ID", required = true, dataType = "long"),
@ApiImplicitParam(name = "id", value = "角色ID", required = true, dataType = "string"),
@ApiImplicitParam(name = "roleForm", value = "角色实体", required = true, dataType = "RoleUpdateForm")
})
@PutMapping(value = "/{id}")
Expand All @@ -51,7 51,7 @@ public Result update(@PathVariable String id, @Valid @RequestBody RoleUpdateForm
}

@ApiOperation(value = "获取角色", notes = "获取指定角色信息")
@ApiImplicitParam(paramType = "path", name = "id", value = "角色ID", required = true, dataType = "long")
@ApiImplicitParam(paramType = "path", name = "id", value = "角色ID", required = true, dataType = "string")
@GetMapping(value = "/{id}")
public Result get(@PathVariable String id) {
log.debug("get with id:{}", id);
Expand All @@ -65,7 65,7 @@ public Result get() {
}

@ApiOperation(value = "查询角色", notes = "根据用户id查询用户所拥有的角色信息")
@ApiImplicitParam(paramType = "path", name = "userId", value = "用户id", required = true, dataType = "long")
@ApiImplicitParam(paramType = "path", name = "userId", value = "用户id", required = true, dataType = "string")
@ApiResponses(
@ApiResponse(code = 200, message = "处理成功", response = Result.class)
)
Expand Down

0 comments on commit 0287117

Please sign in to comment.