add travis ci config

This commit is contained in:
oppofind 2020-09-01 23:17:58 +08:00
parent a7a46fc4c1
commit a2d455d6b7
3 changed files with 50 additions and 43 deletions

10
.travis.yml Normal file
View File

@ -0,0 +1,10 @@
language: java
jdk:
- oraclejdk8
install: mvn install -DskipTests=true -Dmaven.javadoc.skip=true
script: mvn test
after_success:
- mvn clean cobertura:cobertura coveralls:report
env:
global:
secure: xxx

View File

@ -79,7 +79,7 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate<RpcApiDoc> {
return null;
}
public boolean ignoreReturnObject(String typeName,List<String> ignoreParams) {
public boolean ignoreReturnObject(String typeName, List<String> ignoreParams) {
return false;
}
@ -131,7 +131,7 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate<RpcApiDoc> {
}
apiMethodDoc.setDeprecated(deprecated);
// build request params
List<ApiParam> requestParams = requestParams(method, DocTags.PARAM, projectBuilder);
List<ApiParam> requestParams = requestParams(method, projectBuilder);
apiMethodDoc.setRequestParams(requestParams);
// build response params
List<ApiParam> responseParams = buildReturnApiParams(method, projectBuilder);
@ -142,18 +142,17 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate<RpcApiDoc> {
return methodDocList;
}
private List<ApiParam> requestParams(final JavaMethod javaMethod, final String tagName, ProjectDocConfigBuilder builder) {
private List<ApiParam> requestParams(final JavaMethod javaMethod, ProjectDocConfigBuilder builder) {
boolean isStrict = builder.getApiConfig().isStrict();
boolean isShowJavaType = builder.getApiConfig().getShowJavaType();
Map<String, CustomRespField> responseFieldMap = new HashMap<>();
String className = javaMethod.getDeclaringClass().getCanonicalName();
Map<String, String> paramTagMap = DocUtil.getParamsComments(javaMethod, tagName, className);
Map<String, String> paramTagMap = DocUtil.getParamsComments(javaMethod, DocTags.PARAM, className);
List<JavaParameter> parameterList = javaMethod.getParameters();
if (parameterList.size() < 1) {
return null;
}
List<ApiParam> paramList = new ArrayList<>();
out:
for (JavaParameter parameter : parameterList) {
String paramName = parameter.getName();
String typeName = parameter.getType().getGenericCanonicalName();
@ -168,8 +167,6 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate<RpcApiDoc> {
JavaClass javaClass = builder.getJavaProjectBuilder().getClassByName(fullTypeName);
List<JavaAnnotation> annotations = parameter.getAnnotations();
List<String> groupClasses = JavaClassUtil.getParamGroupJavaClass(annotations);
String strRequired = "true";
Boolean required = Boolean.parseBoolean(strRequired);
if (JavaClassValidateUtil.isCollection(fullTypeName) || JavaClassValidateUtil.isArray(fullTypeName)) {
String[] gicNameArr = DocClassUtil.getSimpleGicName(typeName);
String gicName = gicNameArr[0];
@ -183,28 +180,28 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate<RpcApiDoc> {
.setType(processedType);
paramList.add(param);
} else {
paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[0], paramPre, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses,0));
paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[0], paramPre, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses, 0));
}
} else if (JavaClassValidateUtil.isPrimitive(fullTypeName)) {
ApiParam param = ApiParam.of().setField(paramName)
.setType(JavaClassUtil.getClassSimpleName(typeName))
.setDesc(comment).setRequired(required).setVersion(DocGlobalConstants.DEFAULT_VERSION);
.setDesc(comment).setRequired(true).setVersion(DocGlobalConstants.DEFAULT_VERSION);
paramList.add(param);
} else if (JavaClassValidateUtil.isMap(fullTypeName)) {
if (DocGlobalConstants.JAVA_MAP_FULLY.equals(typeName)) {
ApiParam apiParam = ApiParam.of().setField(paramName).setType(typeName)
.setDesc(comment).setRequired(required).setVersion(DocGlobalConstants.DEFAULT_VERSION);
.setDesc(comment).setRequired(true).setVersion(DocGlobalConstants.DEFAULT_VERSION);
paramList.add(apiParam);
continue out;
continue;
}
String[] gicNameArr = DocClassUtil.getSimpleGicName(typeName);
paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[1], paramPre, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses,0));
paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[1], paramPre, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses, 0));
} else if (javaClass.isEnum()) {
ApiParam param = ApiParam.of().setField(paramName)
.setType("Enum").setDesc(comment).setRequired(required).setVersion(DocGlobalConstants.DEFAULT_VERSION);
.setType("Enum").setDesc(comment).setRequired(true).setVersion(DocGlobalConstants.DEFAULT_VERSION);
paramList.add(param);
} else {
paramList.addAll(ParamsBuildHelper.buildParams(typeName, paramPre, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses,0));
paramList.addAll(ParamsBuildHelper.buildParams(typeName, paramPre, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses, 0));
}
}
return paramList;
@ -272,8 +269,8 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate<RpcApiDoc> {
returnClass = returnClass.replace(simpleReturn, JavaClassUtil.getClassSimpleName(simpleReturn));
String[] arrays = DocClassUtil.getSimpleGicName(returnClass);
for (String str : arrays) {
if(str.contains("[")){
str = str.substring(0,str.indexOf("["));
if (str.contains("[")) {
str = str.substring(0, str.indexOf("["));
}
String[] generics = str.split("<");
for (String generic : generics) {

View File

@ -129,8 +129,8 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
methodOrder++;
ApiMethodDoc apiMethodDoc = new ApiMethodDoc();
apiMethodDoc.setOrder(methodOrder);
apiMethodDoc.setDesc(method.getComment());
apiMethodDoc.setName(method.getName());
apiMethodDoc.setDesc(method.getComment());
String methodUid = DocUtil.generateId(clazName + method.getName());
apiMethodDoc.setMethodId(methodUid);
String apiNoteValue = DocUtil.getNormalTagComments(method, DocTags.API_NOTE, cls.getName());
@ -162,7 +162,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
apiMethodDoc.setPath(requestMapping.getShortUrl());
apiMethodDoc.setDeprecated(requestMapping.isDeprecated());
// build request params
List<ApiParam> requestParams = requestParams(method, DocTags.PARAM, projectBuilder);
List<ApiParam> requestParams = requestParams(method, projectBuilder);
if (paramsDataToTree) {
requestParams = ApiParamTreeUtil.apiParamToTree(requestParams);
}
@ -228,18 +228,13 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
String paramName = parameter.getName();
String typeName = javaType.getFullyQualifiedName();
String gicTypeName = javaType.getGenericCanonicalName();
String rewriteClassName = null;
String commentClass = paramsComments.get(paramName);
//ignore request params
if (Objects.nonNull(commentClass) && commentClass.contains(IGNORE)) {
continue;
}
if (Objects.nonNull(commentClass) && !DocGlobalConstants.NO_COMMENTS_FOUND.equals(commentClass)) {
String[] comments = commentClass.split("\\|");
rewriteClassName = comments[comments.length - 1];
} else {
rewriteClassName = replacementMap.get(typeName);
}
String rewriteClassName = this.getRewriteClassName(replacementMap, typeName, commentClass);
// rewrite class
if (DocUtil.isClassName(rewriteClassName)) {
gicTypeName = rewriteClassName;
@ -391,14 +386,14 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
String format = String.format(DocGlobalConstants.CURL_REQUEST_TYPE, methodType, header.toString(), url);
if (requestExample.isJson()) {
if (StringUtil.isNotEmpty(requestExample.getJsonBody())) {
exampleBody = String.format(DocGlobalConstants.CURL_POST_PUT_JSON, methodType,header.toString(), url,
exampleBody = String.format(DocGlobalConstants.CURL_POST_PUT_JSON, methodType, header.toString(), url,
requestExample.getJsonBody());
} else {
exampleBody = format;
}
} else {
if (StringUtil.isNotEmpty(body)) {
exampleBody = String.format(DocGlobalConstants.CURL_REQUEST_TYPE_DATA, methodType,header.toString(), url, body);
exampleBody = String.format(DocGlobalConstants.CURL_REQUEST_TYPE_DATA, methodType, header.toString(), url, body);
} else {
exampleBody = format;
}
@ -412,7 +407,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
url = StringUtil.removeQuotes(url);
url = apiMethodDoc.getServerUrl() + "/" + url;
url = UrlUtil.simplifyUrl(url);
exampleBody = String.format(DocGlobalConstants.CURL_REQUEST_TYPE, methodType,header.toString(), url);
exampleBody = String.format(DocGlobalConstants.CURL_REQUEST_TYPE, methodType, header.toString(), url);
requestExample.setExampleBody(exampleBody)
.setJsonBody(DocGlobalConstants.EMPTY)
.setUrl(url);
@ -420,13 +415,12 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
return requestExample;
}
private List<ApiParam> requestParams(final JavaMethod javaMethod, final String tagName, ProjectDocConfigBuilder builder) {
private List<ApiParam> requestParams(final JavaMethod javaMethod, ProjectDocConfigBuilder builder) {
boolean isStrict = builder.getApiConfig().isStrict();
Map<String, CustomRespField> responseFieldMap = new HashMap<>();
Map<String, String> replacementMap = builder.getReplaceClassMap();
String className = javaMethod.getDeclaringClass().getCanonicalName();
Map<String, String> paramTagMap = DocUtil.getParamsComments(javaMethod, tagName, className);
Map<String, String> replacementMap = builder.getReplaceClassMap();
Map<String, String> paramTagMap = DocUtil.getParamsComments(javaMethod, DocTags.PARAM, className);
List<JavaParameter> parameterList = javaMethod.getParameters();
if (parameterList.size() < 1) {
return null;
@ -441,21 +435,16 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
String typeName = parameter.getType().getGenericCanonicalName();
String simpleName = parameter.getType().getValue().toLowerCase();
String fullTypeName = parameter.getType().getFullyQualifiedName();
String rewriteClassName = null;
String commentClass = paramTagMap.get(paramName);
if (Objects.nonNull(commentClass) && !DocGlobalConstants.NO_COMMENTS_FOUND.equals(commentClass)) {
String[] comments = commentClass.split("\\|");
rewriteClassName = comments[comments.length - 1];
} else {
rewriteClassName = replacementMap.get(fullTypeName);
}
String rewriteClassName = getRewriteClassName(replacementMap, fullTypeName, commentClass);
// rewrite class
if (DocUtil.isClassName(rewriteClassName)) {
typeName = rewriteClassName;
fullTypeName = DocClassUtil.getSimpleName(rewriteClassName);
}
if (JavaClassValidateUtil.isMvcIgnoreParams(typeName, builder.getApiConfig().getIgnoreRequestParams())) {
continue out;
continue;
}
fullTypeName = DocClassUtil.rewriteRequestParam(fullTypeName);
typeName = DocClassUtil.rewriteRequestParam(typeName);
@ -473,7 +462,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
.setId(paramList.size() + 1)
.setDesc(comment).setRequired(true).setVersion(DocGlobalConstants.DEFAULT_VERSION);
paramList.add(param);
continue out;
continue;
}
JavaClass javaClass = builder.getJavaProjectBuilder().getClassByName(fullTypeName);
List<JavaAnnotation> annotations = parameter.getAnnotations();
@ -512,7 +501,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
requestBodyCounter++;
}
}
Boolean required = Boolean.parseBoolean(strRequired);
boolean required = Boolean.parseBoolean(strRequired);
if (isPathVariable) {
comment = comment + " (This is path param)";
}
@ -554,7 +543,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
.setPathParams(isPathVariable)
.setDesc(comment).setRequired(required).setVersion(DocGlobalConstants.DEFAULT_VERSION);
paramList.add(apiParam);
continue out;
continue;
}
String[] gicNameArr = DocClassUtil.getSimpleGicName(typeName);
paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[1], DocGlobalConstants.EMPTY, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses, 0));
@ -605,4 +594,15 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
}
return false;
}
private String getRewriteClassName(Map<String, String> replacementMap, String fullTypeName, String commentClass) {
String rewriteClassName;
if (Objects.nonNull(commentClass) && !DocGlobalConstants.NO_COMMENTS_FOUND.equals(commentClass)) {
String[] comments = commentClass.split("\\|");
rewriteClassName = comments[comments.length - 1];
} else {
rewriteClassName = replacementMap.get(fullTypeName);
}
return rewriteClassName;
}
}