mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
5.0
This commit is contained in:
@@ -23,7 +23,7 @@ public class ExceptionExecutorImpl implements ExceptionExecutor {
|
|||||||
private static final String CONSTRAINT_VIOLATION_EXCEPTION = "ConstraintViolationException";
|
private static final String CONSTRAINT_VIOLATION_EXCEPTION = "ConstraintViolationException";
|
||||||
private static final String OPEN_EXCEPTION = "OpenException";
|
private static final String OPEN_EXCEPTION = "OpenException";
|
||||||
private static final String BIZ_ERROR_REGEX = "<OPEN_ERROR>(.*?)</OPEN_ERROR>";
|
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
|
@Override
|
||||||
public ApiResponse executeException(ApiRequestContext apiRequestContext, Exception e) {
|
public ApiResponse executeException(ApiRequestContext apiRequestContext, Exception e) {
|
||||||
|
@@ -5,30 +5,7 @@
|
|||||||
<version>5.0.0-SNAPSHOT</version>
|
<version>5.0.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>swagger-plugin</name>
|
<name>sop-doc-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>
|
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- Generic properties -->
|
<!-- Generic properties -->
|
||||||
@@ -58,7 +35,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>fastjson</artifactId>
|
<artifactId>fastjson</artifactId>
|
||||||
<version>1.2.83</version>
|
<version>2.0.52</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
@@ -102,13 +79,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.swagger</groupId>
|
<groupId>io.swagger</groupId>
|
||||||
<artifactId>swagger-annotations</artifactId>
|
<artifactId>swagger-annotations</artifactId>
|
||||||
<version>1.5.19</version>
|
<version>1.6.14</version>
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.springfox</groupId>
|
|
||||||
<artifactId>springfox-core</artifactId>
|
|
||||||
<version>2.4.0</version>
|
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@@ -11,10 +11,8 @@ import io.swagger.annotations.ApiModelProperty;
|
|||||||
import org.springframework.core.annotation.AnnotationUtils;
|
import org.springframework.core.annotation.AnnotationUtils;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import sun.reflect.generics.repository.ClassRepository;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.lang.reflect.TypeVariable;
|
import java.lang.reflect.TypeVariable;
|
||||||
@@ -33,6 +31,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析文档信息
|
* 解析文档信息
|
||||||
|
*
|
||||||
* @author tanghc
|
* @author tanghc
|
||||||
*/
|
*/
|
||||||
public class ApiDocBuilder {
|
public class ApiDocBuilder {
|
||||||
@@ -106,6 +105,7 @@ public class ApiDocBuilder {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成文档信息
|
* 生成文档信息
|
||||||
|
*
|
||||||
* @param paramClass 参数类型
|
* @param paramClass 参数类型
|
||||||
* @return 返回文档内容
|
* @return 返回文档内容
|
||||||
*/
|
*/
|
||||||
@@ -120,7 +120,7 @@ public class ApiDocBuilder {
|
|||||||
Class<?> targetClassRef = PluginUtil.isCollectionOrArray(clazz) ? getCollectionElementClass(clazz) : clazz;
|
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");
|
Field body = ReflectionUtils.findField(targetClassRef, "body");
|
||||||
String typeName = ((TypeVariable<?>) body.getGenericType()).getName();
|
String typeName = ((TypeVariable<?>) body.getGenericType()).getName();
|
||||||
targetClassRef = getGenericParamClass(targetClassRef, typeName);
|
targetClassRef = getGenericParamClass(targetClassRef, typeName);
|
||||||
@@ -202,7 +202,7 @@ public class ApiDocBuilder {
|
|||||||
child.setExample(apiParamInfo.getExample());
|
child.setExample(apiParamInfo.getExample());
|
||||||
child.setDescription(apiParamInfo.getValue());
|
child.setDescription(apiParamInfo.getValue());
|
||||||
child.setOrderIndex(apiParamInfo.getPosition());
|
child.setOrderIndex(apiParamInfo.getPosition());
|
||||||
if(!StringUtils.isEmpty(apiParamInfo.getName())){
|
if (!StringUtils.isEmpty(apiParamInfo.getName())) {
|
||||||
child.setName(apiParamInfo.getName());
|
child.setName(apiParamInfo.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -264,7 +264,7 @@ public class ApiDocBuilder {
|
|||||||
elementClass = PluginUtil.getGenericType(genericType);
|
elementClass = PluginUtil.getGenericType(genericType);
|
||||||
if (elementClass instanceof TypeVariable) {
|
if (elementClass instanceof TypeVariable) {
|
||||||
TypeVariable<?> typeVariable = (TypeVariable<?>) elementClass;
|
TypeVariable<?> typeVariable = (TypeVariable<?>) elementClass;
|
||||||
Class<?> genericDeclaration = (Class<?>)typeVariable.getGenericDeclaration();
|
Class<?> genericDeclaration = (Class<?>) typeVariable.getGenericDeclaration();
|
||||||
Class<?> realClass = this.getGenericParamClass(genericDeclaration, typeVariable.getName());
|
Class<?> realClass = this.getGenericParamClass(genericDeclaration, typeVariable.getName());
|
||||||
if (realClass != null) {
|
if (realClass != null) {
|
||||||
elementClass = realClass;
|
elementClass = realClass;
|
||||||
@@ -285,7 +285,7 @@ public class ApiDocBuilder {
|
|||||||
if (isList) {
|
if (isList) {
|
||||||
Class<?> elType = (Class<?>) genericElType;
|
Class<?> elType = (Class<?>) genericElType;
|
||||||
boolean primitive = ClassUtil.isPrimitive(elType.getName());
|
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);
|
List<FieldDocInfo> fieldDocInfos = buildFieldDocInfosByType(elType, true, null);
|
||||||
fieldDocInfo.setChildren(fieldDocInfos);
|
fieldDocInfo.setChildren(fieldDocInfos);
|
||||||
}
|
}
|
||||||
@@ -336,7 +336,7 @@ public class ApiDocBuilder {
|
|||||||
// 解决循环依赖问题
|
// 解决循环依赖问题
|
||||||
boolean cycle = isCycle(clazz, field);
|
boolean cycle = isCycle(clazz, field);
|
||||||
Type genericType = PluginUtil.getGenericType(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()
|
List<FieldDocInfo> children = cycle ? Collections.emptyList()
|
||||||
: buildFieldDocInfosByType(clazz, false, generic);
|
: buildFieldDocInfosByType(clazz, false, generic);
|
||||||
fieldDocInfo.setChildren(children);
|
fieldDocInfo.setChildren(children);
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
<groupId>com.gitee.sop</groupId>
|
<groupId>com.gitee.sop</groupId>
|
||||||
<artifactId>sop-doc-plugin</artifactId>
|
<artifactId>sop-doc-plugin</artifactId>
|
||||||
<version>5.0.0-SNAPSHOT</version>
|
<version>5.0.0-SNAPSHOT</version>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- dubbo依赖 -->
|
<!-- dubbo依赖 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
Reference in New Issue
Block a user