Merge branch 'dev' of https://github.com/shalousun/smart-doc into dev
This commit is contained in:
commit
b4dfb88190
|
@ -134,5 +134,7 @@
|
||||||
2. 修改使用mybatis-plus实体继承Model对象时将log字段输出到文档的问题。
|
2. 修改使用mybatis-plus实体继承Model对象时将log字段输出到文档的问题。
|
||||||
3. 添加对transient修饰字段文档输出开关,默认不输出。
|
3. 添加对transient修饰字段文档输出开关,默认不输出。
|
||||||
4. html文档添加项目名称显示
|
4. html文档添加项目名称显示
|
||||||
|
5. 修改github #4 泛型中Void类型解析死循环
|
||||||
|
6. 修改github #5 简单枚举参数解析空指针异常
|
||||||
|
|
||||||
|
|
|
@ -572,7 +572,7 @@ public class SourceBuilder {
|
||||||
if (!isResp && javaClass.isEnum()) {
|
if (!isResp && javaClass.isEnum()) {
|
||||||
List<JavaMethod> methods = javaClass.getMethods();
|
List<JavaMethod> methods = javaClass.getMethods();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
String reTypeName = null;
|
String reTypeName = "string";
|
||||||
enumOut:
|
enumOut:
|
||||||
for (JavaMethod method : methods) {
|
for (JavaMethod method : methods) {
|
||||||
JavaType type = method.getReturnType();
|
JavaType type = method.getReturnType();
|
||||||
|
@ -958,15 +958,7 @@ public class SourceBuilder {
|
||||||
} else {
|
} else {
|
||||||
JavaClass javaClass = builder.getClassByName(subTypeName);
|
JavaClass javaClass = builder.getClassByName(subTypeName);
|
||||||
if (!isResp && javaClass.isEnum()) {
|
if (!isResp && javaClass.isEnum()) {
|
||||||
List<JavaField> javaFields = javaClass.getEnumConstants();
|
Object value = this.handleEnumValue(javaClass,Boolean.FALSE);
|
||||||
Object value = null;
|
|
||||||
int index = 0;
|
|
||||||
for (JavaField javaField : javaFields) {
|
|
||||||
String simpleName = javaField.getType().getSimpleName();
|
|
||||||
if (!DocClassUtil.isPrimitive(simpleName) && index < 1) {
|
|
||||||
value = javaField.getEnumConstantArguments().get(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
data0.append(value).append(",");
|
data0.append(value).append(",");
|
||||||
} else {
|
} else {
|
||||||
data0.append(buildJson(subTypeName, fieldGicName, responseFieldMap, isResp, counter + 1, registryClasses)).append(",");
|
data0.append(buildJson(subTypeName, fieldGicName, responseFieldMap, isResp, counter + 1, registryClasses)).append(",");
|
||||||
|
@ -994,6 +986,7 @@ public class SourceBuilder {
|
||||||
String simpleTypeName = javaType.getValue();
|
String simpleTypeName = javaType.getValue();
|
||||||
String gicTypeName = javaType.getGenericCanonicalName();
|
String gicTypeName = javaType.getGenericCanonicalName();
|
||||||
String typeName = javaType.getFullyQualifiedName();
|
String typeName = javaType.getFullyQualifiedName();
|
||||||
|
JavaClass javaClass = builder.getClassByName(typeName);
|
||||||
String paraName = parameter.getName();
|
String paraName = parameter.getName();
|
||||||
if (!DocClassUtil.isMvcIgnoreParams(typeName)) {
|
if (!DocClassUtil.isMvcIgnoreParams(typeName)) {
|
||||||
//file upload
|
//file upload
|
||||||
|
@ -1058,10 +1051,12 @@ public class SourceBuilder {
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
if (requestBodyCounter < 1 && paraName != null) {
|
if (requestBodyCounter < 1 && paraName != null) {
|
||||||
if (annotations.size() < 1 && !DocClassUtil.isPrimitive(typeName)) {
|
if (javaClass.isEnum()) {
|
||||||
|
Object value = this.handleEnumValue(javaClass,Boolean.TRUE);
|
||||||
|
paramsMap.put(paraName, StringUtil.removeQuotes(String.valueOf(value)));
|
||||||
|
} else if (annotations.size() < 1 && !DocClassUtil.isPrimitive(typeName)) {
|
||||||
return "Smart-doc can't support create form-data example,It is recommended to use @RequestBody to receive parameters.";
|
return "Smart-doc can't support create form-data example,It is recommended to use @RequestBody to receive parameters.";
|
||||||
}
|
} else if (StringUtil.isEmpty(defaultVal) && DocClassUtil.isPrimitive(typeName)) {
|
||||||
if (StringUtil.isEmpty(defaultVal)) {
|
|
||||||
paramsMap.put(paraName, DocUtil.getValByTypeAndFieldName(simpleTypeName, paraName,
|
paramsMap.put(paraName, DocUtil.getValByTypeAndFieldName(simpleTypeName, paraName,
|
||||||
true));
|
true));
|
||||||
} else {
|
} else {
|
||||||
|
@ -1104,6 +1099,7 @@ public class SourceBuilder {
|
||||||
String typeName = parameter.getType().getGenericCanonicalName();
|
String typeName = parameter.getType().getGenericCanonicalName();
|
||||||
String simpleName = parameter.getType().getValue().toLowerCase();
|
String simpleName = parameter.getType().getValue().toLowerCase();
|
||||||
String fullTypeName = parameter.getType().getFullyQualifiedName();
|
String fullTypeName = parameter.getType().getFullyQualifiedName();
|
||||||
|
JavaClass javaClass = builder.getClassByName(fullTypeName);
|
||||||
if (!DocClassUtil.isMvcIgnoreParams(typeName)) {
|
if (!DocClassUtil.isMvcIgnoreParams(typeName)) {
|
||||||
if (!paramTagMap.containsKey(paramName) && DocClassUtil.isPrimitive(fullTypeName) && isStrict) {
|
if (!paramTagMap.containsKey(paramName) && DocClassUtil.isPrimitive(fullTypeName) && isStrict) {
|
||||||
throw new RuntimeException("ERROR: Unable to find javadoc @param for actual param \""
|
throw new RuntimeException("ERROR: Unable to find javadoc @param for actual param \""
|
||||||
|
@ -1146,6 +1142,10 @@ public class SourceBuilder {
|
||||||
ApiParam param = ApiParam.of().setField(paramName)
|
ApiParam param = ApiParam.of().setField(paramName)
|
||||||
.setType("map").setDesc(comment).setRequired(true).setVersion(DocGlobalConstants.DEFAULT_VERSION);
|
.setType("map").setDesc(comment).setRequired(true).setVersion(DocGlobalConstants.DEFAULT_VERSION);
|
||||||
paramList.add(param);
|
paramList.add(param);
|
||||||
|
} else if (javaClass.isEnum()) {
|
||||||
|
ApiParam param = ApiParam.of().setField(paramName)
|
||||||
|
.setType("string").setDesc(comment).setRequired(true).setVersion(DocGlobalConstants.DEFAULT_VERSION);
|
||||||
|
paramList.add(param);
|
||||||
} else {
|
} else {
|
||||||
paramList.addAll(buildParams(fullTypeName, "", 0, "true", responseFieldMap, false, new HashMap<>()));
|
paramList.addAll(buildParams(fullTypeName, "", 0, "true", responseFieldMap, false, new HashMap<>()));
|
||||||
}
|
}
|
||||||
|
@ -1337,4 +1337,28 @@ public class SourceBuilder {
|
||||||
apiDoc.setList(apiMethodDocs);
|
apiDoc.setList(apiMethodDocs);
|
||||||
apiDocList.add(apiDoc);
|
apiDocList.add(apiDoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object handleEnumValue(JavaClass javaClass,boolean returnEnum) {
|
||||||
|
List<JavaField> javaFields = javaClass.getEnumConstants();
|
||||||
|
Object value = null;
|
||||||
|
int index = 0;
|
||||||
|
for (JavaField javaField : javaFields) {
|
||||||
|
String simpleName = javaField.getType().getSimpleName();
|
||||||
|
StringBuilder valueBuilder = new StringBuilder();
|
||||||
|
valueBuilder.append("\"").append(javaField.getName()).append("\"").toString();
|
||||||
|
if(returnEnum){
|
||||||
|
value = valueBuilder.toString();
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
if (!DocClassUtil.isPrimitive(simpleName) && index < 1) {
|
||||||
|
if (null != javaField.getEnumConstantArguments()) {
|
||||||
|
value = javaField.getEnumConstantArguments().get(0);
|
||||||
|
} else {
|
||||||
|
value = valueBuilder.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.power.doc.utils;
|
package com.power.doc.utils;
|
||||||
|
|
||||||
|
import com.power.common.util.StringUtil;
|
||||||
import com.power.doc.constants.DocGlobalConstants;
|
import com.power.doc.constants.DocGlobalConstants;
|
||||||
import com.power.doc.model.ApiReturn;
|
import com.power.doc.model.ApiReturn;
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ public class DocClassUtil {
|
||||||
type = type.toLowerCase();
|
type = type.toLowerCase();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "integer":
|
case "integer":
|
||||||
case "void":
|
case "void":
|
||||||
case "int":
|
case "int":
|
||||||
case "long":
|
case "long":
|
||||||
case "double":
|
case "double":
|
||||||
|
@ -168,6 +169,9 @@ public class DocClassUtil {
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
public static String processTypeNameForParams(String javaTypeName) {
|
public static String processTypeNameForParams(String javaTypeName) {
|
||||||
|
if (StringUtil.isEmpty(javaTypeName)) {
|
||||||
|
return "object";
|
||||||
|
}
|
||||||
if (javaTypeName.length() == 1) {
|
if (javaTypeName.length() == 1) {
|
||||||
return "object";
|
return "object";
|
||||||
}
|
}
|
||||||
|
@ -388,11 +392,12 @@ public class DocClassUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore field type name
|
* ignore field type name
|
||||||
|
*
|
||||||
* @param typeName field type name
|
* @param typeName field type name
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
public static boolean isIgnoreFieldTypes(String typeName){
|
public static boolean isIgnoreFieldTypes(String typeName) {
|
||||||
switch (typeName) {
|
switch (typeName) {
|
||||||
case "org.slf4j.Logger":
|
case "org.slf4j.Logger":
|
||||||
return true;
|
return true;
|
||||||
|
@ -424,7 +429,7 @@ public class DocClassUtil {
|
||||||
fullyName.startsWith("java.util.concurrent.CompletableFuture") ||
|
fullyName.startsWith("java.util.concurrent.CompletableFuture") ||
|
||||||
fullyName.startsWith("org.springframework.web.context.request.async.DeferredResult") ||
|
fullyName.startsWith("org.springframework.web.context.request.async.DeferredResult") ||
|
||||||
fullyName.startsWith("org.springframework.web.context.request.async.WebAsyncTask") ||
|
fullyName.startsWith("org.springframework.web.context.request.async.WebAsyncTask") ||
|
||||||
fullyName.startsWith("reactor.core.publisher.Mono")||
|
fullyName.startsWith("reactor.core.publisher.Mono") ||
|
||||||
fullyName.startsWith("org.springframework.http.ResponseEntity")) {
|
fullyName.startsWith("org.springframework.http.ResponseEntity")) {
|
||||||
if (fullyName.contains("<")) {
|
if (fullyName.contains("<")) {
|
||||||
String[] strings = getSimpleGicName(fullyName);
|
String[] strings = getSimpleGicName(fullyName);
|
||||||
|
|
Loading…
Reference in New Issue