Compare commits
7 Commits
Author | SHA1 | Date |
---|---|---|
shalousun | d72404af10 | |
shalousun | 3c0108ed15 | |
shalousun | 6049e33b8d | |
shalousun | c4fcf6d561 | |
shalousun | ad47c6094b | |
shalousun | 146387c1fb | |
shalousun | d75e388db1 |
|
@ -11,7 +11,7 @@
|
|||
5. 修复maven插件torna-rest和torna-rpc两个task未加编译前缀的问题。
|
||||
6. 修复生成json用例中数组类型json错误的问题。
|
||||
7. 修复customRequestFields中设置字段value在用例中不生效的bug。
|
||||
|
||||
8. 修改基础数组类型字段formdata生成样例错误
|
||||
#### 版本号:2.1.7
|
||||
|
||||
- 更新日期: 2020-05-12
|
||||
|
|
|
@ -39,7 +39,7 @@ public class ApiDataBuilder {
|
|||
* @return List of ApiDoc
|
||||
*/
|
||||
public static ApiAllData getApiData(ApiConfig config) {
|
||||
return getApiData(config, false);
|
||||
return getApiData(config, Boolean.FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,7 +49,7 @@ public class ApiDataBuilder {
|
|||
* @return List of ApiDoc
|
||||
*/
|
||||
public static ApiAllData getApiDataTree(ApiConfig config) {
|
||||
return getApiData(config, true);
|
||||
return getApiData(config, Boolean.TRUE);
|
||||
}
|
||||
|
||||
private static ApiAllData getApiData(ApiConfig config, boolean toTree) {
|
||||
|
@ -57,7 +57,7 @@ public class ApiDataBuilder {
|
|||
DocBuilderTemplate builderTemplate = new DocBuilderTemplate();
|
||||
builderTemplate.checkAndInitForGetApiData(config);
|
||||
JavaProjectBuilder javaProjectBuilder = new JavaProjectBuilder();
|
||||
builderTemplate.getApiData(config, javaProjectBuilder);
|
||||
return builderTemplate.getApiData(config, javaProjectBuilder);
|
||||
ApiAllData apiAllData = builderTemplate.getApiData(config, javaProjectBuilder);
|
||||
return apiAllData;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -322,6 +322,7 @@ public class DocBuilderTemplate extends BaseDocBuilderTemplate {
|
|||
config.setMd5EncryptedHtmlName(true);
|
||||
ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder);
|
||||
IDocBuildTemplate docBuildTemplate = new SpringBootDocBuildTemplate();
|
||||
return docBuildTemplate.getApiData(configBuilder);
|
||||
List<ApiDoc> apiDocList = docBuildTemplate.getApiData(configBuilder);
|
||||
return apiDocList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,14 +158,28 @@ public class FormDataBuildHelper {
|
|||
formData.setValue(StringUtil.removeQuotes(String.valueOf(value)));
|
||||
formData.setDescription(comment);
|
||||
formDataList.add(formData);
|
||||
} else if (JavaClassValidateUtil.isCollection(subTypeName)) {
|
||||
} else if (JavaClassValidateUtil.isCollection(subTypeName) || JavaClassValidateUtil.isArray(subTypeName)) {
|
||||
String gNameTemp = field.getType().getGenericCanonicalName();
|
||||
String[] gNameArr = DocClassUtil.getSimpleGicName(gNameTemp);
|
||||
if (gNameArr.length == 0) {
|
||||
continue out;
|
||||
}
|
||||
String gName = DocClassUtil.getSimpleGicName(gNameTemp)[0];
|
||||
if (!JavaClassValidateUtil.isPrimitive(gName)) {
|
||||
if (JavaClassValidateUtil.isPrimitive(gName)) {
|
||||
String fieldValue = "";
|
||||
if (tagsMap.containsKey(DocTags.MOCK) && StringUtil.isNotEmpty(tagsMap.get(DocTags.MOCK))) {
|
||||
fieldValue = tagsMap.get(DocTags.MOCK);
|
||||
} else {
|
||||
String val = DocUtil.getValByTypeAndFieldName(gName, field.getName());
|
||||
fieldValue = val + "," + val;
|
||||
}
|
||||
FormData formData = new FormData();
|
||||
formData.setKey(pre + fieldName);
|
||||
formData.setType("text");
|
||||
formData.setValue(fieldValue);
|
||||
formData.setDescription(comment);
|
||||
formDataList.add(formData);
|
||||
} else {
|
||||
if (!simpleName.equals(gName) && !gName.equals(simpleName)) {
|
||||
if (gName.length() == 1) {
|
||||
int len = globGicName.length;
|
||||
|
|
|
@ -276,25 +276,6 @@ public class ParamsBuildHelper {
|
|||
commonHandleParam(paramList, param, isRequired, NO_COMMENTS_FOUND, since, strRequired);
|
||||
}
|
||||
} else {
|
||||
ApiParam param = ApiParam.of().setField(pre + fieldName).setPid(pid).setMaxLength(maxLength);
|
||||
JavaClass javaClass = projectBuilder.getJavaProjectBuilder().getClassByName(subTypeName);
|
||||
if (javaClass.isEnum()) {
|
||||
comment = comment + handleEnumComment(javaClass, projectBuilder);
|
||||
param.setType(DocGlobalConstants.ENUM);
|
||||
}
|
||||
if (JavaClassValidateUtil.isCollection(subTypeName)) {
|
||||
String gNameTemp = fieldGicName;
|
||||
// like Student<T>, Student class has a field List<T> lists.
|
||||
if (globGicName.length > 0 && JAVA_LIST_FULLY.equals(gNameTemp)) {
|
||||
gNameTemp = gNameTemp + "<T>";
|
||||
}
|
||||
String[] gNameArr = DocClassUtil.getSimpleGicName(gNameTemp);
|
||||
if (gNameArr.length > 0) {
|
||||
String gName = DocClassUtil.getSimpleGicName(gNameTemp)[0];
|
||||
JavaClass javaClass1 = projectBuilder.getJavaProjectBuilder().getClassByName(gName);
|
||||
comment = comment + handleEnumComment(javaClass1, projectBuilder);
|
||||
}
|
||||
}
|
||||
String appendComment = "";
|
||||
if (displayActualType) {
|
||||
if (globGicName.length > 0) {
|
||||
|
@ -307,8 +288,15 @@ public class ParamsBuildHelper {
|
|||
appendComment = " (ActualType: " + JavaClassUtil.getClassSimpleName(docField.getActualJavaType()) + ")";
|
||||
}
|
||||
}
|
||||
//如果已经设置返回类型 不需要再次设置
|
||||
if (param.getType() == null) {
|
||||
|
||||
StringBuilder preBuilder = new StringBuilder();
|
||||
for (int j = 0; j < level; j++) {
|
||||
preBuilder.append(DocGlobalConstants.FIELD_SPACE);
|
||||
}
|
||||
preBuilder.append("└─");
|
||||
int fieldPid;
|
||||
ApiParam param = ApiParam.of().setField(pre + fieldName).setPid(pid).setMaxLength(maxLength);
|
||||
|
||||
String processedType;
|
||||
if (typeSimpleName.length() == 1) {
|
||||
processedType = DocClassUtil.processTypeNameForParams(typeSimpleName.toLowerCase());
|
||||
|
@ -316,11 +304,13 @@ public class ParamsBuildHelper {
|
|||
processedType = isShowJavaType ? typeSimpleName : DocClassUtil.processTypeNameForParams(typeSimpleName.toLowerCase());
|
||||
}
|
||||
param.setType(processedType);
|
||||
}
|
||||
if (!isResp && javaClass.isEnum()) {
|
||||
JavaClass javaClass = projectBuilder.getJavaProjectBuilder().getClassByName(subTypeName);
|
||||
if (javaClass.isEnum()) {
|
||||
comment = comment + handleEnumComment(javaClass, projectBuilder);
|
||||
param.setType(DocGlobalConstants.ENUM);
|
||||
if (!isResp) {
|
||||
List<JavaMethod> methods = javaClass.getMethods();
|
||||
int index = 0;
|
||||
|
||||
enumOut:
|
||||
for (JavaMethod method : methods) {
|
||||
List<JavaAnnotation> javaAnnotationList = method.getAnnotations();
|
||||
|
@ -337,54 +327,53 @@ public class ParamsBuildHelper {
|
|||
Object value = JavaClassUtil.getEnumValue(javaClass, !jsonRequest);
|
||||
param.setValue(String.valueOf(value));
|
||||
param.setEnumValues(JavaClassUtil.getEnumValues(javaClass));
|
||||
param.setType(DocGlobalConstants.ENUM);
|
||||
}
|
||||
if (StringUtil.isNotEmpty(comment)) {
|
||||
commonHandleParam(paramList, param, isRequired, comment + appendComment, since, strRequired);
|
||||
} else {
|
||||
commonHandleParam(paramList, param, isRequired, NO_COMMENTS_FOUND + appendComment, since, strRequired);
|
||||
}
|
||||
StringBuilder preBuilder = new StringBuilder();
|
||||
for (int j = 0; j < level; j++) {
|
||||
preBuilder.append(DocGlobalConstants.FIELD_SPACE);
|
||||
|
||||
} else if (JavaClassValidateUtil.isCollection(subTypeName) || JavaClassValidateUtil.isArray(subTypeName)) {
|
||||
param.setType("array");
|
||||
if (globGicName.length > 0 && "java.util.List".equals(fieldGicName)) {
|
||||
fieldGicName = fieldGicName + "<T>";
|
||||
}
|
||||
preBuilder.append("└─");
|
||||
int fieldPid = paramList.size() + pid;
|
||||
if (JavaClassValidateUtil.isMap(subTypeName)) {
|
||||
String gNameTemp = fieldGicName;
|
||||
String valType = DocClassUtil.getMapKeyValueType(gNameTemp).length == 0 ? gNameTemp : DocClassUtil.getMapKeyValueType(gNameTemp)[1];
|
||||
if (JavaClassValidateUtil.isMap(gNameTemp) || JAVA_OBJECT_FULLY.equals(valType)) {
|
||||
ApiParam param1 = ApiParam.of().setField(preBuilder.toString() + "any object")
|
||||
.setId(fieldPid + 1).setPid(fieldPid)
|
||||
.setMaxLength(maxLength)
|
||||
.setType("object").setDesc(DocGlobalConstants.ANY_OBJECT_MSG).setVersion(DocGlobalConstants.DEFAULT_VERSION);
|
||||
paramList.add(param1);
|
||||
continue;
|
||||
if (JavaClassValidateUtil.isArray(subTypeName)) {
|
||||
fieldGicName = fieldGicName.substring(0, fieldGicName.lastIndexOf("["));
|
||||
fieldGicName = "java.util.List<" + fieldGicName + ">";
|
||||
}
|
||||
if (!JavaClassValidateUtil.isPrimitive(valType)) {
|
||||
if (valType.length() == 1) {
|
||||
String gicName = genericMap.get(valType);
|
||||
if (!JavaClassValidateUtil.isPrimitive(gicName) && !simpleName.equals(gicName)) {
|
||||
paramList.addAll(buildParams(gicName, preBuilder.toString(), nextLevel, isRequired,
|
||||
isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest));
|
||||
}
|
||||
} else {
|
||||
paramList.addAll(buildParams(valType, preBuilder.toString(), nextLevel, isRequired,
|
||||
isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest));
|
||||
}
|
||||
}
|
||||
} else if (JavaClassValidateUtil.isCollection(subTypeName)) {
|
||||
String gNameTemp = fieldGicName;
|
||||
if (globGicName.length > 0 && JAVA_LIST_FULLY.equals(gNameTemp)) {
|
||||
gNameTemp = gNameTemp + "<T>";
|
||||
}
|
||||
String[] gNameArr = DocClassUtil.getSimpleGicName(gNameTemp);
|
||||
String[] gNameArr = DocClassUtil.getSimpleGicName(fieldGicName);
|
||||
if (gNameArr.length == 0) {
|
||||
continue out;
|
||||
}
|
||||
String gName = DocClassUtil.getSimpleGicName(gNameTemp)[0];
|
||||
|
||||
if (!JavaClassValidateUtil.isPrimitive(gName)) {
|
||||
if (gNameArr.length > 0) {
|
||||
String gName = DocClassUtil.getSimpleGicName(fieldGicName)[0];
|
||||
JavaClass javaClass1 = projectBuilder.getJavaProjectBuilder().getClassByName(gName);
|
||||
comment = comment + handleEnumComment(javaClass1, projectBuilder);
|
||||
}
|
||||
String gName = gNameArr[0];
|
||||
if (JavaClassValidateUtil.isPrimitive(gName)) {
|
||||
String builder = DocUtil.jsonValueByType(gName) +
|
||||
"," +
|
||||
DocUtil.jsonValueByType(gName);
|
||||
if (StringUtil.isEmpty(fieldValue)) {
|
||||
param.setValue(DocUtil.handleJsonStr(builder));
|
||||
} else {
|
||||
param.setValue(fieldValue);
|
||||
}
|
||||
if (StringUtil.isNotEmpty(comment)) {
|
||||
commonHandleParam(paramList, param, isRequired, comment + appendComment, since, strRequired);
|
||||
} else {
|
||||
commonHandleParam(paramList, param, isRequired, NO_COMMENTS_FOUND + appendComment, since, strRequired);
|
||||
}
|
||||
} else {
|
||||
if (StringUtil.isNotEmpty(comment)) {
|
||||
commonHandleParam(paramList, param, isRequired, comment + appendComment, since, strRequired);
|
||||
} else {
|
||||
commonHandleParam(paramList, param, isRequired, NO_COMMENTS_FOUND + appendComment, since, strRequired);
|
||||
}
|
||||
fieldPid = paramList.size() + pid;
|
||||
if (!simpleName.equals(gName) && !gName.equals(simpleName)) {
|
||||
JavaClass arraySubClass = projectBuilder.getJavaProjectBuilder().getClassByName(gName);
|
||||
if (arraySubClass.isEnum()) {
|
||||
|
@ -408,19 +397,44 @@ public class ParamsBuildHelper {
|
|||
isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (JavaClassValidateUtil.isMap(subTypeName)) {
|
||||
if (StringUtil.isNotEmpty(comment)) {
|
||||
commonHandleParam(paramList, param, isRequired, comment + appendComment, since, strRequired);
|
||||
} else {
|
||||
String builder = "[" +
|
||||
DocUtil.jsonValueByType(gName) +
|
||||
"," +
|
||||
DocUtil.jsonValueByType(gName) +
|
||||
"]";
|
||||
if (StringUtil.isEmpty(fieldValue)) {
|
||||
param.setValue(DocUtil.handleJsonStr(builder));
|
||||
commonHandleParam(paramList, param, isRequired, NO_COMMENTS_FOUND + appendComment, since, strRequired);
|
||||
}
|
||||
fieldPid = paramList.size() + pid;
|
||||
String gNameTemp = fieldGicName;
|
||||
String valType = DocClassUtil.getMapKeyValueType(gNameTemp).length == 0 ? gNameTemp : DocClassUtil.getMapKeyValueType(gNameTemp)[1];
|
||||
if (JavaClassValidateUtil.isMap(gNameTemp) || JAVA_OBJECT_FULLY.equals(valType)) {
|
||||
ApiParam param1 = ApiParam.of().setField(preBuilder.toString() + "any object")
|
||||
.setId(fieldPid + 1).setPid(fieldPid)
|
||||
.setMaxLength(maxLength)
|
||||
.setType("object").setDesc(DocGlobalConstants.ANY_OBJECT_MSG).setVersion(DocGlobalConstants.DEFAULT_VERSION);
|
||||
paramList.add(param1);
|
||||
continue;
|
||||
}
|
||||
if (!JavaClassValidateUtil.isPrimitive(valType)) {
|
||||
if (valType.length() == 1) {
|
||||
String gicName = genericMap.get(valType);
|
||||
if (!JavaClassValidateUtil.isPrimitive(gicName) && !simpleName.equals(gicName)) {
|
||||
paramList.addAll(buildParams(gicName, preBuilder.toString(), nextLevel, isRequired,
|
||||
isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest));
|
||||
}
|
||||
} else {
|
||||
param.setValue(fieldValue);
|
||||
paramList.addAll(buildParams(valType, preBuilder.toString(), nextLevel, isRequired,
|
||||
isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest));
|
||||
}
|
||||
}
|
||||
} else if (subTypeName.length() == 1 || DocGlobalConstants.JAVA_OBJECT_FULLY.equals(subTypeName)) {
|
||||
if (StringUtil.isNotEmpty(comment)) {
|
||||
commonHandleParam(paramList, param, isRequired, comment + appendComment, since, strRequired);
|
||||
} else {
|
||||
commonHandleParam(paramList, param, isRequired, NO_COMMENTS_FOUND + appendComment, since, strRequired);
|
||||
}
|
||||
fieldPid = paramList.size() + pid;
|
||||
// handle java generic or object
|
||||
if (DocGlobalConstants.JAVA_OBJECT_FULLY.equals(subTypeName) && StringUtil.isNotEmpty(field.getComment())) {
|
||||
ApiParam param1 = ApiParam.of().setField(preBuilder.toString() + "any object")
|
||||
|
@ -461,21 +475,18 @@ public class ParamsBuildHelper {
|
|||
isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest));
|
||||
}
|
||||
}
|
||||
} else if (JavaClassValidateUtil.isArray(subTypeName)) {
|
||||
fieldGicName = fieldGicName.substring(0, fieldGicName.indexOf("["));
|
||||
if (className.equals(fieldGicName)) {
|
||||
//do nothing
|
||||
} else if (!JavaClassValidateUtil.isPrimitive(fieldGicName)) {
|
||||
paramList.addAll(buildParams(fieldGicName, preBuilder.toString(), nextLevel, isRequired,
|
||||
isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest));
|
||||
}
|
||||
} else if (simpleName.equals(subTypeName)) {
|
||||
//do nothing
|
||||
} else {
|
||||
if (!javaClass.isEnum()) {
|
||||
if (StringUtil.isNotEmpty(comment)) {
|
||||
commonHandleParam(paramList, param, isRequired, comment + appendComment, since, strRequired);
|
||||
} else {
|
||||
commonHandleParam(paramList, param, isRequired, NO_COMMENTS_FOUND + appendComment, since, strRequired);
|
||||
}
|
||||
fieldPid = paramList.size() + pid;
|
||||
paramList.addAll(buildParams(fieldGicName, preBuilder.toString(), nextLevel, isRequired,
|
||||
isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}//end field
|
||||
|
|
|
@ -823,9 +823,14 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
|
|||
}
|
||||
|
||||
private boolean checkController(JavaClass cls) {
|
||||
if (cls.isAnnotation() || cls.isEnum()) {
|
||||
return false;
|
||||
}
|
||||
JavaClass superClass = cls.getSuperJavaClass();
|
||||
List<JavaAnnotation> classAnnotations = new ArrayList<>();
|
||||
if (Objects.nonNull(superClass)) {
|
||||
classAnnotations.addAll(superClass.getAnnotations());
|
||||
}
|
||||
classAnnotations.addAll(cls.getAnnotations());
|
||||
for (JavaAnnotation annotation : classAnnotations) {
|
||||
String name = annotation.getType().getValue();
|
||||
|
@ -928,7 +933,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
|
|||
return annotationsList;
|
||||
}
|
||||
JavaClass superJavaClass = cls.getSuperJavaClass();
|
||||
if (!"Object".equals(superJavaClass.getSimpleName())) {
|
||||
if (Objects.nonNull(superJavaClass) && !"Object".equals(superJavaClass.getSimpleName())) {
|
||||
annotationsList.addAll(getAnnotations(superJavaClass));
|
||||
}
|
||||
return annotationsList;
|
||||
|
|
Loading…
Reference in New Issue