1. 临时提交,system 的 rpc 服务的 swagger 注解的实现

This commit is contained in:
YunaiV
2022-06-03 17:46:54 +08:00
parent e89ef5496c
commit 0fcd30bbfd
24 changed files with 213 additions and 352 deletions

View File

@@ -22,6 +22,13 @@
<artifactId>yudao-common</artifactId>
</dependency>
<!-- Web 相关 -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<optional>true</optional>
</dependency>
<!-- 参数校验 -->
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@@ -1,58 +0,0 @@
package cn.iocoder.yudao.module.system.api.auth;
import cn.iocoder.yudao.module.system.api.auth.dto.OAuth2AccessTokenCheckRespDTO;
import cn.iocoder.yudao.module.system.api.auth.dto.OAuth2AccessTokenCreateReqDTO;
import cn.iocoder.yudao.module.system.api.auth.dto.OAuth2AccessTokenRespDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.validation.Valid;
/**
* OAuth2.0 Token API 接口
*
* @author 芋道源码
*/
@FeignClient(name = "system-server") // TODO 芋艿fallbackFactory =
public interface OAuth2TokenApi {
/**
* 创建访问令牌
*
* @param reqDTO 访问令牌的创建信息
* @return 访问令牌的信息
*/
@GetMapping("/tmp")
OAuth2AccessTokenRespDTO createAccessToken(@Valid OAuth2AccessTokenCreateReqDTO reqDTO);
/**
* 校验访问令牌
*
* @param accessToken 访问令牌
* @return 访问令牌的信息
*/
@GetMapping("/app-api/check")
OAuth2AccessTokenCheckRespDTO checkAccessToken(@RequestParam("accessToken") String accessToken);
/**
* 移除访问令牌
*
* @param accessToken 访问令牌
* @return 访问令牌的信息
*/
@GetMapping("/tmp2")
OAuth2AccessTokenRespDTO removeAccessToken(String accessToken);
/**
* 刷新访问令牌
*
* @param refreshToken 刷新令牌
* @param clientId 客户端编号
* @return 访问令牌的信息
*/
@GetMapping("/tmp3")
OAuth2AccessTokenRespDTO refreshAccessToken(@RequestParam("refreshToken") String refreshToken,
@RequestParam("clientId") String clientId);
}

View File

@@ -1,33 +0,0 @@
package cn.iocoder.yudao.module.system.api.auth.dto;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* OAuth2.0 访问令牌的校验 Response DTO
*
* @author 芋道源码
*/
@Data
public class OAuth2AccessTokenCheckRespDTO implements Serializable {
/**
* 用户编号
*/
private Long userId;
/**
* 用户类型
*/
private Integer userType;
/**
* 租户编号
*/
private Long tenantId;
/**
* 授权范围的数组
*/
private List<String> scopes;
}

View File

@@ -1,39 +0,0 @@
package cn.iocoder.yudao.module.system.api.auth.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* OAuth2.0 访问令牌的信息 Response DTO
*
* @author 芋道源码
*/
@Data
@Accessors(chain = true)
public class OAuth2AccessTokenRespDTO implements Serializable {
/**
* 访问令牌
*/
private String accessToken;
/**
* 刷新令牌
*/
private String refreshToken;
/**
* 用户编号
*/
private Long userId;
/**
* 用户类型
*/
private Integer userType;
/**
* 过期时间
*/
private Date expiresTime;
}

View File

@@ -0,0 +1,46 @@
package cn.iocoder.yudao.module.system.api.oauth2;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO;
import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCreateReqDTO;
import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenRespDTO;
import cn.iocoder.yudao.module.system.enums.ApiConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
@FeignClient(name = "system-server") // TODO 芋艿fallbackFactory =
@Api(tags = "RPC 服务 - OAuth2.0 令牌")
public interface OAuth2TokenApi {
String API_PREFIX = ApiConstants.API_PREFIX + "/oauth2/token";
@PostMapping(API_PREFIX + "/create")
@ApiOperation("创建访问令牌")
CommonResult<OAuth2AccessTokenRespDTO> createAccessToken(@Valid @RequestBody OAuth2AccessTokenCreateReqDTO reqDTO);
@GetMapping(API_PREFIX + "/check")
@ApiOperation("校验访问令牌")
@ApiImplicitParam(name = "accessToken", value = "访问令牌", required = true, example = "tudou")
CommonResult<OAuth2AccessTokenCheckRespDTO> checkAccessToken(@RequestParam("accessToken") String accessToken);
@DeleteMapping(API_PREFIX + "/remove")
@ApiOperation("移除访问令牌")
@ApiImplicitParam(name = "accessToken", value = "访问令牌", required = true, example = "tudou")
CommonResult<OAuth2AccessTokenRespDTO> removeAccessToken(@RequestParam("accessToken") String accessToken);
@PutMapping(API_PREFIX + "/refresh")
@ApiOperation("刷新访问令牌")
@ApiImplicitParams({
@ApiImplicitParam(name = "refreshToken", value = "刷新令牌", required = true, example = "haha"),
@ApiImplicitParam(name = "clientId", value = "客户端编号", required = true, example = "yudaoyuanma")
})
CommonResult<OAuth2AccessTokenRespDTO> refreshAccessToken(@RequestParam("refreshToken") String refreshToken,
@RequestParam("clientId") String clientId);
}

View File

@@ -0,0 +1,26 @@
package cn.iocoder.yudao.module.system.api.oauth2.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@ApiModel("RPC 服务 - OAuth2.0 访问令牌的校验 Response DTO")
@Data
public class OAuth2AccessTokenCheckRespDTO implements Serializable {
@ApiModelProperty(value = "用户编号", required = true, example = "10")
private Long userId;
@ApiModelProperty(value = "用户类型", required = true, example = "1", notes = "参见 UserTypeEnum 枚举")
private Integer userType;
@ApiModelProperty(value = "租户编号", required = true, example = "1024")
private Long tenantId;
@ApiModelProperty(value = "授权范围的数组", example = "user_info")
private List<String> scopes;
}

View File

@@ -1,40 +1,33 @@
package cn.iocoder.yudao.module.system.api.auth.dto;
package cn.iocoder.yudao.module.system.api.oauth2.dto;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
/**
* OAuth2.0 访问令牌创建 Request DTO
*
* @author 芋道源码
*/
@ApiModel("RPC 服务 - OAuth2.0 访问令牌创建 Request DTO")
@Data
public class OAuth2AccessTokenCreateReqDTO implements Serializable {
/**
* 用户编号
*/
@ApiModelProperty(value = "用户编号", required = true, example = "10")
@NotNull(message = "用户编号不能为空")
private Long userId;
/**
* 用户类型
*/
@ApiModelProperty(value = "用户类型", required = true, example = "1", notes = "参见 UserTypeEnum 枚举")
@NotNull(message = "用户类型不能为空")
@InEnum(value = UserTypeEnum.class, message = "用户类型必须是 {value}")
private Integer userType;
/**
* 客户端编号
*/
@ApiModelProperty(value = "客户端编号", required = true, example = "yudaoyuanma")
@NotNull(message = "客户端编号不能为空")
private String clientId;
/**
* 授权范围
*/
@ApiModelProperty(value = "授权范围的数组", example = "user_info")
private List<String> scopes;
}

View File

@@ -0,0 +1,31 @@
package cn.iocoder.yudao.module.system.api.oauth2.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
@ApiModel("RPC 服务 - OAuth2.0 访问令牌的信息 Response DTO")
@Data
@Accessors(chain = true)
public class OAuth2AccessTokenRespDTO implements Serializable {
@ApiModelProperty(value = "访问令牌", required = true, example = "tudou")
private String accessToken;
@ApiModelProperty(value = "刷新令牌", required = true, example = "haha")
private String refreshToken;
@ApiModelProperty(value = "用户编号", required = true, example = "10")
private Long userId;
@ApiModelProperty(value = "用户类型", required = true, example = "1", notes = "参见 UserTypeEnum 枚举")
private Integer userType;
@ApiModelProperty(value = "过期时间", required = true)
private Date expiresTime;
}

View File

@@ -0,0 +1,12 @@
package cn.iocoder.yudao.module.system.enums;
/**
* API 相关的枚举
*
* @author 芋道源码
*/
public class ApiConstants {
public static final String API_PREFIX = "/rpc-api/system";
}