feat:gitee #I1ADFQ

This commit is contained in:
songhaozhi 2020-03-20 23:30:57 +08:00
parent ee8a79d837
commit a6b435e7f5
3 changed files with 291 additions and 256 deletions

View File

@ -99,6 +99,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
private List<ApiMethodDoc> buildControllerMethod(final JavaClass cls, ApiConfig apiConfig, ProjectDocConfigBuilder projectBuilder) {
String clazName = cls.getCanonicalName();
String classAuthor = JavaClassUtil.getClassTagsValue(cls, DocTags.AUTHOR);
List<JavaAnnotation> classAnnotations = cls.getAnnotations();
String baseUrl = "";
for (JavaAnnotation annotation : classAnnotations) {
@ -130,10 +131,14 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
if (StringUtil.isEmpty(apiNoteValue)) {
apiNoteValue = method.getComment();
}
String authorValue = DocUtil.getNormalTagComments(method, DocTags.AUTHOR, cls.getName());
Map<String, String> authorMap = DocUtil.getParamsComments(method, DocTags.AUTHOR, cls.getName());
String authorValue = String.join(", ", new ArrayList<>(authorMap.keySet()));
if (apiConfig.isShowAuthor() && StringUtil.isNotEmpty(authorValue)) {
apiMethodDoc.setAuthor(authorValue);
}
if (apiConfig.isShowAuthor() && StringUtil.isEmpty(authorValue)) {
apiMethodDoc.setAuthor(classAuthor);
}
apiMethodDoc.setDetail(apiNoteValue);
//handle request mapping
RequestMapping requestMapping = new SpringMVCRequestMappingHandler()
@ -192,7 +197,8 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
List<String> springMvcRequestAnnotations = SpringMvcRequestAnnotationsEnum.listSpringMvcRequestAnnotations();
List<FormData> formDataList = new ArrayList<>();
ApiRequestExample requestExample = ApiRequestExample.builder();
out:for (JavaParameter parameter : parameterList) {
out:
for (JavaParameter parameter : parameterList) {
JavaType javaType = parameter.getType();
String typeName = javaType.getFullyQualifiedName();
if (JavaClassValidateUtil.isMvcIgnoreParams(typeName)) {
@ -436,14 +442,14 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
}
if (JavaClassValidateUtil.isPrimitive(gicName)) {
String shortSimple = DocClassUtil.processTypeNameForParams(gicName);
ApiParam param = ApiParam.of().setField(paramName).setDesc(comment+",[array of "+shortSimple+"]" )
ApiParam param = ApiParam.of().setField(paramName).setDesc(comment + ",[array of " + shortSimple + "]")
.setRequired(required)
.setType("array");
paramList.add(param);
} else {
if (requestBodyCounter > 0) {
//for json
paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[0], DocGlobalConstants.ENMPTY, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder,groupClasses));
paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[0], DocGlobalConstants.ENMPTY, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses));
} else {
throw new RuntimeException("Spring MVC can't support binding Collection on method "
+ javaMethod.getName() + "Check it in " + javaMethod.getDeclaringClass().getCanonicalName());
@ -462,13 +468,13 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
continue out;
}
String[] gicNameArr = DocClassUtil.getSimpleGicName(typeName);
paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[1], DocGlobalConstants.ENMPTY, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder,groupClasses));
paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[1], DocGlobalConstants.ENMPTY, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses));
} else if (javaClass.isEnum()) {
ApiParam param = ApiParam.of().setField(paramName)
.setType("string").setDesc(comment).setRequired(required).setVersion(DocGlobalConstants.DEFAULT_VERSION);
paramList.add(param);
} else {
paramList.addAll(ParamsBuildHelper.buildParams(fullTypeName, DocGlobalConstants.ENMPTY, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder,groupClasses));
paramList.addAll(ParamsBuildHelper.buildParams(fullTypeName, DocGlobalConstants.ENMPTY, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses));
}
}
return paramList;

View File

@ -327,8 +327,8 @@ public class DocUtil {
pName = value.substring(0, idx);
pValue = value.substring(idx + 1);
} else {
pName = (value.indexOf(" ") > -1) ? value.substring(0, value.indexOf(" ")) : value;
pValue = value.indexOf(" ") > -1 ? value.substring(value.indexOf(' ') + 1) : DocGlobalConstants.NO_COMMENTS_FOUND;
pName = (value.contains(" ")) ? value.substring(0, value.indexOf(" ")) : value;
pValue = value.contains(" ") ? value.substring(value.indexOf(' ') + 1) : DocGlobalConstants.NO_COMMENTS_FOUND;
}
paramTagMap.put(pName, pValue);
}

View File

@ -35,7 +35,6 @@ import com.thoughtworks.qdox.model.expression.TypeRef;
import com.thoughtworks.qdox.model.impl.DefaultJavaField;
import com.thoughtworks.qdox.model.impl.DefaultJavaParameterizedType;
import javax.print.Doc;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@ -82,7 +81,7 @@ public class JavaClassUtil {
JavaClass pcls = cls1.getSuperJavaClass();
fieldList.addAll(getFields(pcls, i));
List<DocJavaField> docJavaFields = new ArrayList<>();
for(JavaField javaField:cls1.getFields()){
for (JavaField javaField : cls1.getFields()) {
docJavaFields.add(DocJavaField.builder().setComment(javaField.getComment()).setJavaField(javaField));
}
fieldList.addAll(docJavaFields);
@ -197,7 +196,7 @@ public class JavaClassUtil {
List<String> javaClassList = new ArrayList<>();
List<String> validates = DocValidatorAnnotationEnum.listValidatorAnnotations();
for (JavaAnnotation javaAnnotation : annotations) {
List<AnnotationValue> annotationValueList = getAnnotationValues(validates,javaAnnotation);
List<AnnotationValue> annotationValueList = getAnnotationValues(validates, javaAnnotation);
addGroupClass(annotationValueList, javaClassList);
}
return javaClassList;
@ -205,6 +204,7 @@ public class JavaClassUtil {
/**
* Obtain Validate Group classes
*
* @param javaAnnotation the annotation of controller method param
* @return the group annotation value
*/
@ -214,11 +214,40 @@ public class JavaClassUtil {
}
List<String> javaClassList = new ArrayList<>();
List<String> validates = DocValidatorAnnotationEnum.listValidatorAnnotations();
List<AnnotationValue> annotationValueList = getAnnotationValues(validates,javaAnnotation);
List<AnnotationValue> annotationValueList = getAnnotationValues(validates, javaAnnotation);
addGroupClass(annotationValueList, javaClassList);
return javaClassList;
}
/**
* 通过name获取类标签的value
*
* @param cls
* @param tagName 需要获取的标签name
* @return 类标签的value
* @author songhaozhi
*/
public static String getClassTagsValue(final JavaClass cls, final String tagName) {
if (StringUtil.isNotEmpty(tagName)) {
StringBuilder result = new StringBuilder();
List<DocletTag> tags = cls.getTags();
for (int i = 0; i < tags.size(); i++) {
String value = tags.get(i).getValue();
if (StringUtil.isEmpty(value)) {
throw new RuntimeException("ERROR: #" + cls.getName()
+ "() - bad @" + tagName + " javadoc from " + cls.getName() + ", must be add comment if you use it.");
}
if (tagName.equals(tags.get(i).getName())) {
if (i != 0) {
result.append(",");
}
result.append(value);
}
}
return result.toString();
}
return null;
}
private static void addGroupClass(List<AnnotationValue> annotationValueList, List<String> javaClassList) {
if (CollectionUtil.isEmpty(annotationValueList)) {
@ -231,7 +260,7 @@ public class JavaClassUtil {
}
}
private static List<AnnotationValue> getAnnotationValues(List<String> validates,JavaAnnotation javaAnnotation){
private static List<AnnotationValue> getAnnotationValues(List<String> validates, JavaAnnotation javaAnnotation) {
List<AnnotationValue> annotationValueList = null;
String simpleName = javaAnnotation.getType().getSimpleName();
if (simpleName.equalsIgnoreCase(ValidatorAnnotations.VALIDATED)) {