Skip to content

Commit

Permalink
Merge pull request #557 from netdied/master
Browse files Browse the repository at this point in the history
feat:支持torna版本号
  • Loading branch information
shalousun authored Jul 28, 2023
2 parents 071750e + 17016c8 commit 7ae3a58
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 8 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/power/doc/model/ApiMethodDoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,20 @@ public class ApiMethodDoc implements Serializable, Cloneable {
*/
private String[] tags;

/**
* 版本号
*/
private String version;

public String getVersion() {
return version;
}

public ApiMethodDoc setVersion(String version) {
this.version = version;
return this;
}

private final Set<TagDoc> tagRefs = Collections.synchronizedSet(new LinkedHashSet<>());

public Integer getIsRequestArray() {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/power/doc/model/DocJavaMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ public class DocJavaMethod {

Map<String, String> paramsComments;

private String version;

public String getVersion() {
return version;
}

public DocJavaMethod setVersion(String version) {
this.version = version;
return this;
}

public static DocJavaMethod builder() {
return new DocJavaMethod();
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/power/doc/model/RpcJavaMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ public class RpcJavaMethod {

private Map<String, JavaType> actualTypesMap;


private String version;

public String getVersion() {
return version;
}

public RpcJavaMethod setVersion(String version) {
this.version = version;
return this;
}

public static RpcJavaMethod builder() {
return new RpcJavaMethod();
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/power/doc/template/IRestDocTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ default List<ApiMethodDoc> buildEntryPointMethod(
apiMethodDoc.setDownload(docJavaMethod.isDownload());
apiMethodDoc.setPage(docJavaMethod.getPage());
apiMethodDoc.setGroup(group);
apiMethodDoc.setVersion(docJavaMethod.getVersion());
if (Objects.nonNull(docJavaMethod.getGroup())) {
apiMethodDoc.setGroup(docJavaMethod.getGroup());
}
Expand Down Expand Up @@ -1105,6 +1106,8 @@ default DocJavaMethod convertToDocJavaMethod(ApiConfig apiConfig, ProjectDocConf

String comment = DocUtil.getEscapeAndCleanComment(method.getComment());
docJavaMethod.setDesc(comment);
String version = DocUtil.getNormalTagComments(method, DocTags.SINCE, cls.getName());
docJavaMethod.setVersion(version);

String apiNoteValue = DocUtil.getNormalTagComments(method, DocTags.API_NOTE, cls.getName());
if (StringUtil.isEmpty(apiNoteValue)) {
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/com/power/doc/template/IRpcDocTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ default RpcJavaMethod convertToRpcJavaMethod(ApiConfig apiConfig, JavaMethod met
if (StringUtil.isEmpty(apiNoteValue)) {
apiNoteValue = method.getComment();
}
String version = DocUtil.getNormalTagComments(method, DocTags.SINCE, cls.getName());
rpcJavaMethod.setVersion(version);
rpcJavaMethod.setDetail(apiNoteValue != null ? apiNoteValue : "");
// set author
String authorValue = DocUtil.getNormalTagComments(method, DocTags.AUTHOR, cls.getName());
Expand All @@ -90,8 +92,8 @@ default RpcJavaMethod convertToRpcJavaMethod(ApiConfig apiConfig, JavaMethod met
default String methodDefinition(JavaMethod method, Map<String, JavaType> actualTypesMap) {
StringBuilder methodBuilder = new StringBuilder();
JavaType returnType = method.getReturnType();
String simpleReturn = replaceTypeName(returnType.getCanonicalName(),actualTypesMap,Boolean.TRUE);
String returnClass = replaceTypeName(returnType.getGenericCanonicalName(),actualTypesMap,Boolean.TRUE);
String simpleReturn = replaceTypeName(returnType.getCanonicalName(), actualTypesMap, Boolean.TRUE);
String returnClass = replaceTypeName(returnType.getGenericCanonicalName(), actualTypesMap, Boolean.TRUE);
returnClass = returnClass.replace(simpleReturn, JavaClassUtil.getClassSimpleName(simpleReturn));
String[] arrays = DocClassUtil.getSimpleGicName(returnClass);
for (String str : arrays) {
Expand All @@ -114,7 +116,7 @@ default String methodDefinition(JavaMethod method, Map<String, JavaType> actualT
List<String> params = new ArrayList<>();
List<JavaParameter> parameters = method.getParameters();
for (JavaParameter parameter : parameters) {
String typeName = replaceTypeName(parameter.getType().getGenericValue(),actualTypesMap,Boolean.TRUE);
String typeName = replaceTypeName(parameter.getType().getGenericValue(), actualTypesMap, Boolean.TRUE);
params.add(typeName + " " + parameter.getName());
}
methodBuilder.append(method.getName()).append("(")
Expand All @@ -136,17 +138,17 @@ default List<RpcJavaMethod> getParentsClassMethods(ApiConfig apiConfig, JavaClas
return docJavaMethods;
}

default String replaceTypeName(String type,Map<String, JavaType> actualTypesMap,boolean simple){
default String replaceTypeName(String type, Map<String, JavaType> actualTypesMap, boolean simple) {
if (Objects.isNull(actualTypesMap)) {
return type;
}

for (Map.Entry<String,JavaType> entry:actualTypesMap.entrySet()){
for (Map.Entry<String, JavaType> entry : actualTypesMap.entrySet()) {
if (type.contains(entry.getKey())) {
if(simple) {
return type.replace(entry.getKey(),entry.getValue().getGenericValue());
if (simple) {
return type.replace(entry.getKey(), entry.getValue().getGenericValue());
} else {
return type.replace(entry.getKey(),entry.getValue().getGenericFullyQualifiedName());
return type.replace(entry.getKey(), entry.getValue().getGenericFullyQualifiedName());
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/power/doc/utils/TornaUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public static List<Apis> buildApis(List<ApiMethodDoc> apiMethodDocs, boolean has
methodApi.setIsShow(TornaConstants.YES);
methodApi.setAuthor(apiMethodDoc.getAuthor());
methodApi.setOrderIndex(apiMethodDoc.getOrder());
methodApi.setVersion(apiMethodDoc.getVersion());

methodApi.setHeaderParams(buildHerder(apiMethodDoc.getRequestHeaders()));
methodApi.setResponseParams(buildParams(apiMethodDoc.getResponseParams()));
Expand Down

0 comments on commit 7ae3a58

Please sign in to comment.