ApiMethodDoc add methodId and name field

This commit is contained in:
oppofind 2019-10-22 22:41:43 +08:00
parent d9544c0c69
commit 8ff4760deb
3 changed files with 48 additions and 1 deletions

View File

@ -58,6 +58,7 @@ public class ApiDocBuilder {
public static List<ApiDoc> listOfApiData(ApiConfig config) {
DocBuilderTemplate builderTemplate = new DocBuilderTemplate();
builderTemplate.checkAndInitForGetApiData(config);
config.setMd5EncryptedHtmlName(true);
SourceBuilder sourceBuilder = new SourceBuilder(config);
return sourceBuilder.getControllerApiData();
}
@ -72,6 +73,7 @@ public class ApiDocBuilder {
public static ApiDoc getApiData(ApiConfig config, String controllerName) {
DocBuilderTemplate builderTemplate = new DocBuilderTemplate();
builderTemplate.checkAndInitForGetApiData(config);
config.setMd5EncryptedHtmlName(true);
SourceBuilder sourceBuilder = new SourceBuilder(config);
return sourceBuilder.getSingleControllerApiData(controllerName);
}

View File

@ -149,6 +149,7 @@ public class SourceBuilder {
}
private List<ApiMethodDoc> buildControllerMethod(final JavaClass cls) {
String clazName = cls.getCanonicalName();
List<JavaAnnotation> classAnnotations = cls.getAnnotations();
String baseUrl = "";
for (JavaAnnotation annotation : classAnnotations) {
@ -173,6 +174,9 @@ public class SourceBuilder {
ApiMethodDoc apiMethodDoc = new ApiMethodDoc();
apiMethodDoc.setOrder(methodOrder);
apiMethodDoc.setDesc(method.getComment());
apiMethodDoc.setName(method.getName());
String methodUid = clazName + method.getName();
this.handleMethodUid(apiMethodDoc, methodUid);
String apiNoteValue = DocUtil.getNormalTagComments(method, DocTags.API_NOTE, cls.getName());
if (StringUtil.isEmpty(apiNoteValue)) {
apiNoteValue = method.getComment();
@ -978,7 +982,7 @@ public class SourceBuilder {
return builder.toString();
}
if (requestBodyCounter < 1 && paraName != null) {
if(annotations.size()<1&& !DocClassUtil.isPrimitive(typeName)){
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.";
}
if (StringUtil.isEmpty(defaultVal)) {
@ -1211,6 +1215,16 @@ public class SourceBuilder {
}
}
private void handleMethodUid(ApiMethodDoc methodDoc, String methodName) {
String name = DigestUtils.md5Hex(methodName);
int length = name.length();
if (name.length() < 32) {
methodDoc.setMethodId(name);
} else {
methodDoc.setMethodId(name.substring(length - 32, length));
}
}
private void commonHandleParam(List<ApiParam> paramList, ApiParam param, String isRequired, String comment, String since, boolean strRequired) {
if (StringUtil.isEmpty(isRequired)) {
param.setDesc(comment).setVersion(since);

View File

@ -10,6 +10,20 @@ public class ApiMethodDoc implements Serializable {
private static final long serialVersionUID = 7211922919532562867L;
/**
* methodId handled by md5
* @since 1.7.3 +
*
*/
private String methodId;
/**
* method name
* @since 1.7.3 +
*/
private String name;
/**
* method order
*
@ -17,6 +31,7 @@ public class ApiMethodDoc implements Serializable {
*/
private int order;
/**
* method description
*/
@ -75,6 +90,22 @@ public class ApiMethodDoc implements Serializable {
private List<ApiParam> responseParams;
public String getMethodId() {
return methodId;
}
public void setMethodId(String methodId) {
this.methodId = methodId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDesc() {
return desc;
}