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

View File

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