package cn.torna.swaggerplugin;
import cn.torna.sdk.client.OpenClient;
import cn.torna.sdk.param.DebugEnv;
import cn.torna.sdk.param.DocItem;
import cn.torna.sdk.param.DocParamCode;
import cn.torna.sdk.param.DocParamHeader;
import cn.torna.sdk.param.DocParamPath;
import cn.torna.sdk.param.DocParamReq;
import cn.torna.sdk.param.DocParamResp;
import cn.torna.sdk.param.EnumInfoParam;
import cn.torna.sdk.param.IParam;
import cn.torna.sdk.request.DocPushRequest;
import cn.torna.sdk.request.EnumBatchPushRequest;
import cn.torna.sdk.response.DocPushResponse;
import cn.torna.sdk.response.EnumPushResponse;
import cn.torna.swaggerplugin.bean.ApiParamWrapper;
import cn.torna.swaggerplugin.bean.Booleans;
import cn.torna.swaggerplugin.bean.CodeInfo;
import cn.torna.swaggerplugin.bean.CodeItem;
import cn.torna.swaggerplugin.bean.ControllerInfo;
import cn.torna.swaggerplugin.bean.DocParamInfo;
import cn.torna.swaggerplugin.bean.ModeEnum;
import cn.torna.swaggerplugin.bean.PluginConstants;
import cn.torna.swaggerplugin.bean.PushFeature;
import cn.torna.swaggerplugin.bean.TornaConfig;
import cn.torna.swaggerplugin.builder.ApiDocBuilder;
import cn.torna.swaggerplugin.builder.DataType;
import cn.torna.swaggerplugin.builder.FieldDocInfo;
import cn.torna.swaggerplugin.builder.MvcRequestInfoBuilder;
import cn.torna.swaggerplugin.builder.RequestInfoBuilder;
import cn.torna.swaggerplugin.exception.HiddenException;
import cn.torna.swaggerplugin.exception.IgnoreException;
import cn.torna.swaggerplugin.util.ClassUtil;
import cn.torna.swaggerplugin.util.PluginUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializerFeature;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpMethod;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @author tanghc
*/
public class SwaggerPluginService {
private final TornaConfig tornaConfig;
private final OpenClient client;
private boolean existsApiIgnore = true;
public SwaggerPluginService(TornaConfig tornaConfig) {
this.tornaConfig = tornaConfig;
client = new OpenClient(tornaConfig.getUrl());
try {
Class.forName("springfox.documentation.annotations.ApiIgnore");
} catch (ClassNotFoundException e) {
existsApiIgnore = false;
System.out.println("Warning: no 'springfox-core' dependency is imported, 'ApiIgnore' check will be skipped.");
}
}
public void pushDoc() {
if (!tornaConfig.getEnable()) {
return;
}
String basePackage = tornaConfig.getBasePackage();
if (StringUtils.isEmpty(basePackage)) {
throw new IllegalArgumentException("basePackage can not empty.");
}
this.doPush();
this.pushCode();
}
protected void doPush() {
String packageConfig = tornaConfig.getBasePackage();
String[] pkgs = packageConfig.split(";");
Set<Class<?>> classes = new HashSet<>();
for (String basePackage : pkgs) {
Set<Class<?>> clazzs = ClassUtil.getClasses(basePackage, Api.class);
classes.addAll(clazzs);
}
Map<ControllerInfo, List<DocItem>> controllerDocMap = new HashMap<>(32);
for (Class<?> clazz : classes) {
ControllerInfo controllerInfo;
try {
controllerInfo = buildControllerInfo(clazz);
} catch (HiddenException | IgnoreException e) {
System.out.println(e.getMessage());
continue;
}
List<DocItem> docItems = controllerDocMap.computeIfAbsent(controllerInfo, k -> new ArrayList<>());
ReflectionUtils.doWithMethods(clazz, method -> {
try {
DocItem apiInfo = buildDocItem(new MvcRequestInfoBuilder(method, tornaConfig));
docItems.add(apiInfo);
} catch (HiddenException | IgnoreException e) {
System.out.println(e.getMessage());
} catch (Exception e) {
System.out.printf("Create doc error, method:%s%n", method);
throw new RuntimeException(e.getMessage(), e);
}
}, this::match);
}
List<DocItem> docItems = mergeSameFolder(controllerDocMap);
this.push(docItems);
}
/**
* 推送错误码
*/
protected void pushCode() {
List<CodeInfo> codes = this.tornaConfig.getCodes();
if (CollectionUtils.isEmpty(codes)) {
return;
}
checkCode(codes);
formatCode(codes);
String json = JSONArray.toJSONString(codes);
List<EnumInfoParam> enumInfoParams = JSONArray.parseArray(json, EnumInfoParam.class);
String token = tornaConfig.getToken();
EnumBatchPushRequest request = new EnumBatchPushRequest(token);
request.setEnums(enumInfoParams);
// 发送请求
EnumPushResponse response = client.execute(request);
if (!response.isSuccess()) {
System.out.println("Push code error,errorCode:" + response.getCode() + ",errorMsg:" + response.getMsg());
}
}
private void checkCode(List<CodeInfo> codeInfos) {
for (CodeInfo codeInfo : codeInfos) {
if (StringUtils.isEmpty(codeInfo.getName())) {
throw getDefineCodeException("missing code name");
}
List<CodeItem> items = codeInfo.getItems();
if (CollectionUtils.isEmpty(items)) {
throw getDefineCodeException("missing code items");
}
for (CodeItem item : items) {
if (StringUtils.isEmpty(item.getValue())) {
throw getDefineCodeException("missing item.value");
}
if (StringUtils.isEmpty(item.getDescription())) {
throw getDefineCodeException("missing item.description");
}
}
}
}
private static IllegalArgumentException getDefineCodeException(String msg) {
return new IllegalArgumentException("Define code error, " + msg);
}
private void formatCode(List<CodeInfo> codeInfos) {
for (CodeInfo codeInfo : codeInfos) {
List<CodeItem> items = codeInfo.getItems();
if (CollectionUtils.isEmpty(items)) {
continue;
}
for (CodeItem item : items) {
if (StringUtils.isEmpty(item.getType())) {
String type = codeInfo.getItemType();
item.setType(StringUtils.isEmpty(type) ? "string" :
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
本源码项目是基于Java的Torna接口文档管理解决方案设计,包含1096个文件,主要使用Java、Vue、JavaScript、Shell、HTML和CSS编程语言。Torna旨在提供一个方便、快捷的接口文档管理解决方案,采用团队协作的方式管理和维护接口文档,支持不同形式的文档统一维护,以提高团队协作效率和接口文档的管理质量。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java的Torna接口文档管理解决方案设计源码 (1090个子文件)
build.bat 516B
startup.bat 111B
build.bat 65B
my.cnf 391B
iconfont.css 235B
.env.development 630B
Dockerfile 2KB
Dockerfile 356B
.dockerignore 54B
.editorconfig 243B
.eslintignore 34B
spring.factories 231B
spring.factories 224B
.gitignore 348B
.gitignore 326B
.gitignore 249B
.gitignore 203B
dingding_qr.html 2KB
dingding_auth.html 2KB
dingding_qr_result.html 632B
index.html 620B
favicon.ico 66KB
SwaggerPluginService.java 42KB
SwaggerApi.java 36KB
DocInfoService.java 35KB
UpgradeService.java 27KB
SwaggerDocParserV3.java 24KB
DocApi.java 22KB
DocImportService.java 21KB
SwaggerDocParserV2.java 21KB
ApiDocBuilder.java 19KB
HttpHelper.java 18KB
ModuleConfigService.java 14KB
DingTalkController.java 14KB
PluginUtil.java 14KB
ProjectService.java 14KB
DocController.java 13KB
SpaceService.java 12KB
ModuleSettingController.java 12KB
MSApiUtil.java 12KB
DocDiffDetailService.java 11KB
UserInfoService.java 11KB
SdkTest.java 11KB
MockUtilTest.java 10KB
ShareConfigService.java 10KB
DocDiffRecordService.java 10KB
ViewController.java 9KB
MockConfigService.java 9KB
ModuleController.java 9KB
ConvertService.java 8KB
ModuleEnvironmentService.java 8KB
ConcurrentDocPushTest.java 8KB
LdapLoginManager.java 8KB
DocPushTest.java 8KB
DocPushMoreTest.java 7KB
DocPushOverrideTest.java 7KB
DocPushArrayTest.java 7KB
DocPushLevelTest.java 7KB
ComposeDocController.java 7KB
ModuleService.java 7KB
YapiApi.java 7KB
CopyUtil.java 7KB
MeterSphereService.java 7KB
DocParamService.java 7KB
IdGen.java 6KB
DocPushMapTest.java 6KB
ShareController.java 6KB
WebConfig.java 6KB
HttpTest.java 6KB
DubboPushTest.java 6KB
UserMessageService.java 6KB
UserController.java 6KB
ModuleEnvironmentController.java 6KB
EnumService.java 6KB
DebugController.java 6KB
DocInfoDTO.java 6KB
EnvironmentKeys.java 6KB
MockConfigController.java 6KB
UserInfoController.java 6KB
ComposeProjectSettingController.java 6KB
MessageService.java 5KB
MeterSpherePushService.java 5KB
CodingUtil.java 5KB
DocPushItemParam.java 5KB
ComposeAdditionalPageController.java 5KB
UserContext.java 5KB
DefaultThirdPartyLoginManager.java 5KB
MockController.java 5KB
ClassUtil.java 5KB
ConfigController.java 4KB
BaseService.java 4KB
ShareConfigController.java 4KB
OpenApiDocFileCreator.java 4KB
MockUtil.java 4KB
DocItem.java 4KB
OauthController.java 4KB
ModuleEnvironmentParamController.java 4KB
RequestUtil.java 4KB
SystemConfigService.java 4KB
ComposeProjectService.java 4KB
共 1090 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
沐知全栈开发
- 粉丝: 5704
- 资源: 5223
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功