This commit is contained in:
六如
2024-11-04 16:23:16 +08:00
parent 9b2dc49a03
commit f72fd07ea4
4 changed files with 12 additions and 40 deletions

View File

@@ -23,7 +23,7 @@ public class ExceptionExecutorImpl implements ExceptionExecutor {
private static final String CONSTRAINT_VIOLATION_EXCEPTION = "ConstraintViolationException";
private static final String OPEN_EXCEPTION = "OpenException";
private static final String BIZ_ERROR_REGEX = "<OPEN_ERROR>(.*?)</OPEN_ERROR>";
static Pattern PATTERN = Pattern.compile(BIZ_ERROR_REGEX, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
private static final Pattern PATTERN = Pattern.compile(BIZ_ERROR_REGEX, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
@Override
public ApiResponse executeException(ApiRequestContext apiRequestContext, Exception e) {

View File

@@ -5,30 +5,7 @@
<version>5.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>swagger-plugin</name>
<description>Swagger plugin for Torna</description>
<url>https://gitee.com/durcframework/torna</url>
<licenses>
<license>
<name>MIT</name>
<url>https://mit-license.org/</url>
</license>
</licenses>
<developers>
<developer>
<name>tanghc</name>
<email>thc8719@163.com</email>
<organization>gitee</organization>
<organizationUrl>https://gitee.com/durcframework/torna</organizationUrl>
</developer>
</developers>
<scm>
<connection>scm:git:https://gitee.com/durcframework/torna.git</connection>
<developerConnection>scm:git:https://gitee.com/durcframework/torna.git</developerConnection>
<url>https://gitee.com/durcframework/torna.git</url>
<tag>HEAD</tag>
</scm>
<name>sop-doc-plugin</name>
<properties>
<!-- Generic properties -->
@@ -58,7 +35,7 @@
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
<version>2.0.52</version>
</dependency>
<dependency>
<groupId>junit</groupId>
@@ -102,13 +79,7 @@
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.19</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-core</artifactId>
<version>2.4.0</version>
<version>1.6.14</version>
<optional>true</optional>
</dependency>
</dependencies>

View File

@@ -11,10 +11,8 @@ import io.swagger.annotations.ApiModelProperty;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
import sun.reflect.generics.repository.ClassRepository;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
@@ -33,6 +31,7 @@ import java.util.concurrent.atomic.AtomicInteger;
/**
* 解析文档信息
*
* @author tanghc
*/
public class ApiDocBuilder {
@@ -106,6 +105,7 @@ public class ApiDocBuilder {
/**
* 生成文档信息
*
* @param paramClass 参数类型
* @return 返回文档内容
*/
@@ -120,7 +120,7 @@ public class ApiDocBuilder {
Class<?> targetClassRef = PluginUtil.isCollectionOrArray(clazz) ? getCollectionElementClass(clazz) : clazz;
// 查找泛型
if(targetClassRef.getName().equals("org.springframework.http.ResponseEntity")){
if (targetClassRef.getName().equals("org.springframework.http.ResponseEntity")) {
Field body = ReflectionUtils.findField(targetClassRef, "body");
String typeName = ((TypeVariable<?>) body.getGenericType()).getName();
targetClassRef = getGenericParamClass(targetClassRef, typeName);
@@ -202,7 +202,7 @@ public class ApiDocBuilder {
child.setExample(apiParamInfo.getExample());
child.setDescription(apiParamInfo.getValue());
child.setOrderIndex(apiParamInfo.getPosition());
if(!StringUtils.isEmpty(apiParamInfo.getName())){
if (!StringUtils.isEmpty(apiParamInfo.getName())) {
child.setName(apiParamInfo.getName());
}
}
@@ -264,7 +264,7 @@ public class ApiDocBuilder {
elementClass = PluginUtil.getGenericType(genericType);
if (elementClass instanceof TypeVariable) {
TypeVariable<?> typeVariable = (TypeVariable<?>) elementClass;
Class<?> genericDeclaration = (Class<?>)typeVariable.getGenericDeclaration();
Class<?> genericDeclaration = (Class<?>) typeVariable.getGenericDeclaration();
Class<?> realClass = this.getGenericParamClass(genericDeclaration, typeVariable.getName());
if (realClass != null) {
elementClass = realClass;
@@ -285,7 +285,7 @@ public class ApiDocBuilder {
if (isList) {
Class<?> elType = (Class<?>) genericElType;
boolean primitive = ClassUtil.isPrimitive(elType.getName());
fieldDocInfo.setType("List<List<"+ (primitive ? elType.getSimpleName() : "Object") +">>");
fieldDocInfo.setType("List<List<" + (primitive ? elType.getSimpleName() : "Object") + ">>");
List<FieldDocInfo> fieldDocInfos = buildFieldDocInfosByType(elType, true, null);
fieldDocInfo.setChildren(fieldDocInfos);
}
@@ -336,7 +336,7 @@ public class ApiDocBuilder {
// 解决循环依赖问题
boolean cycle = isCycle(clazz, field);
Type genericType = PluginUtil.getGenericType(field);
Class<?> generic = genericType instanceof Class<?> && genericType != clazz? (Class<?>) genericType : null;
Class<?> generic = genericType instanceof Class<?> && genericType != clazz ? (Class<?>) genericType : null;
List<FieldDocInfo> children = cycle ? Collections.emptyList()
: buildFieldDocInfosByType(clazz, false, generic);
fieldDocInfo.setChildren(children);

View File

@@ -29,6 +29,7 @@
<groupId>com.gitee.sop</groupId>
<artifactId>sop-doc-plugin</artifactId>
<version>5.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<!-- dubbo依赖 -->
<dependency>