This commit is contained in:
oppofind 2020-12-31 23:40:14 +08:00
parent d7bf31732b
commit 43a0d1430c
4 changed files with 22 additions and 8 deletions

View File

@ -65,7 +65,7 @@
<dependency>
<groupId>com.github.shalousun</groupId>
<artifactId>common-util</artifactId>
<version>2.0.2</version>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>

View File

@ -197,5 +197,7 @@ public interface DocGlobalConstants {
String YAPI_RESULT_TPL = "yapiJson.btl";
String YAPI_JSON="/yapi.json";
String YAPI_JSON = "/yapi.json";
String DUBBO_SWAGGER = "org.apache.dubbo.rpc.protocol.rest.integration.swagger.DubboSwaggerApiListingResource";
}

View File

@ -132,7 +132,7 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate<RpcApiDoc> {
apiMethodDoc.setMethodDefinition(methodDefine);
apiMethodDoc.setEscapeMethodDefinition(scapeMethod);
apiMethodDoc.setOrder(methodOrder);
apiMethodDoc.setDesc(method.getComment());
apiMethodDoc.setDesc(DocUtil.getEscapeAndCleanComment(method.getComment()));
apiMethodDoc.setName(method.getName());
String methodUid = DocUtil.generateId(clazName + method.getName());
apiMethodDoc.setMethodId(methodUid);
@ -228,6 +228,10 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate<RpcApiDoc> {
private boolean checkDubboInterface(JavaClass cls) {
// Exclude DubboSwaggerService from dubbo 2.7.x
if (DocGlobalConstants.DUBBO_SWAGGER.equals(cls.getCanonicalName())) {
return false;
}
List<JavaAnnotation> classAnnotations = cls.getAnnotations();
for (JavaAnnotation annotation : classAnnotations) {
String name = annotation.getType().getCanonicalName();
@ -250,14 +254,22 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate<RpcApiDoc> {
private void handleJavaApiDoc(JavaClass cls, List<RpcApiDoc> apiDocList, List<JavaMethodDoc> apiMethodDocs,
int order, ProjectDocConfigBuilder builder) {
String className = cls.getCanonicalName();
String shortName = cls.getName();
String comment = cls.getComment();
List<JavaType> javaTypes = cls.getImplements();
if (javaTypes.size() >= 1 && !cls.isInterface()) {
className = javaTypes.get(0).getCanonicalName();
JavaType javaType = javaTypes.get(0);
className = javaType.getCanonicalName();
shortName = className;
JavaClass javaClass = builder.getClassByName(className);
if (StringUtil.isEmpty(comment) && Objects.nonNull(javaClass)) {
comment = javaClass.getComment();
}
}
RpcApiDoc apiDoc = new RpcApiDoc();
apiDoc.setOrder(order);
apiDoc.setName(className);
apiDoc.setShortName(cls.getName());
apiDoc.setShortName(shortName);
apiDoc.setAlias(className);
apiDoc.setUri(builder.getServerUrl() + "/" + className);
apiDoc.setProtocol("dubbo");
@ -265,9 +277,8 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate<RpcApiDoc> {
String name = DocUtil.generateId(apiDoc.getName());
apiDoc.setAlias(name);
}
apiDoc.setDesc(cls.getComment());
apiDoc.setDesc(DocUtil.getEscapeAndCleanComment(comment));
apiDoc.setList(apiMethodDocs);
apiDocList.add(apiDoc);
List<DocletTag> docletTags = cls.getTags();
List<String> authorList = new ArrayList<>();
for (DocletTag docletTag : docletTags) {
@ -280,6 +291,7 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate<RpcApiDoc> {
}
}
apiDoc.setAuthor(String.join(", ", authorList));
apiDocList.add(apiDoc);
}
private String methodDefinition(JavaMethod method) {

View File

@ -6,7 +6,7 @@
&lt;/dependency&gt;
<%}%>
</pre>
</div></div><%if(isNotEmpty(consumerConfigExample)){%><div class="paragraph"><p>Consumer config</p></div><div class="listingblock"><div class="content"><pre>${consumerConfigExample}</pre></div></div><%}%></div></div><%}%><%for(api in apiDocList){%><div class="sect1"><h2 id="_${api.desc}"><a class="anchor"href="#_${api.desc}"></a><a class="link"href="#_${api.desc}">${api.order+1}.&nbsp;${api.desc}</a></h2><div class="sectionbody"><div class="paragraph"><p><strong>URI:</strong>${api.uri}</p></div><div class="paragraph"><p><strong>Service:</strong>${api.name}</p></div><div class="paragraph"><p><strong>Protocol:</strong>${api.protocol}</p></div><div class="paragraph"><p><strong>Author:</strong>${api.author}</p></div><div class="paragraph"><p><strong>Version:</strong>${api.version}</p></div><%for(doc in api.list){%><div class="sect2"><h3 id="_${api.order+1}_${doc.order}_${doc.desc}"><a class="anchor"href="#_${api.order+1}_${doc.order}_${doc.desc}"></a><%if(doc.deprecated){%><a class="link"href="#_${api.order+1}_${doc.order}_${doc.desc}">${api.order+1}.${doc.order}.&nbsp;<span class="line-through">${doc.desc}</span></a><%}else{%><a class="link"href="#_${api.order+1}_${doc.order}_${doc.desc}">${api.order+1}.${doc.order}.&nbsp;${doc.desc}</a><%}%></h3><div class="paragraph"><p><strong>Definition:</strong>&nbsp;${doc.escapeMethodDefinition}</p></div><div class="paragraph"><p><strong>Description:</strong>&nbsp;${doc.detail}</p></div><%if(isNotEmpty(doc.requestParams)){%><div class="paragraph"><p><strong>Invoke-parameters:</strong></p></div><table class="tableblock frame-all grid-all spread"><colgroup><col style="width: 20%;"><col style="width: 20%;"><col style="width: 20%;"><col style="width: 20%;"><col style="width: 20%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Parameter</th><th class="tableblock halign-left valign-top">Type</th><th class="tableblock halign-left valign-top">Description</th><th class="tableblock halign-left valign-top">Required</th><th class="tableblock halign-left valign-top">Since</th></tr></thead><tbody><%for(param in doc.requestParams){%><tr><td class="tableblock halign-left valign-top"><p class="tableblock">${param.field}</p></td><td class="tableblock halign-left valign-top"><p class="tableblock">${param.type}</p></td><td class="tableblock halign-left valign-top"><p class="tableblock">${param.desc}</p></td><td class="tableblock halign-left valign-top"><p class="tableblock">${param.required}</p></td><td class="tableblock halign-left valign-top"><p class="tableblock">${param.version}</p></td></tr><%}%></tbody></table><%}%><%if(isNotEmpty(doc.responseParams)){%><div class="paragraph"><p><strong>Response-fields:</strong></p></div><table class="tableblock frame-all grid-all spread"><colgroup><col style="width: 25%;"><col style="width: 25%;"><col style="width: 25%;"><col style="width: 25%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Field</th><th class="tableblock halign-left valign-top">Type</th><th class="tableblock halign-left valign-top">Description</th><th class="tableblock halign-left valign-top">Since</th></tr></thead><tbody><%for(param in doc.responseParams){%><tr><td class="tableblock halign-left valign-top"><p class="tableblock">${param.field}</p></td><td class="tableblock halign-left valign-top"><p class="tableblock">${param.type}</p></td><td class="tableblock halign-left valign-top"><p class="tableblock">${param.desc}</p></td><td class="tableblock halign-left valign-top"><p class="tableblock">${param.version}</p></td></tr><%}%></tbody></table><%}%></div><%}%></div></div><%}%><%if(isNotEmpty(errorCodeList)){%><div class="sect1"><h2 id="_error_code_list"><a class="anchor"href="#_error_code_list"></a><a class="link"href="#_error_code_list">${apiDocList.~size+2}.&nbsp;${errorListTitle}</a></h2><div class="sectionbody"><table class="tableblock frame-all grid-all spread"><colgroup><col style="width: 50%;"><col style="width: 50%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Error code</th><th class="tableblock halign-left valign-top">Description</th></tr></thead><tbody><%for(error in errorCodeList){%><tr><td class="tableblock halign-left valign-top"><p class="tableblock">${error.value}</p></td><td class="tableblock halign-left valign-top"><p class="tableblock">${error.desc}</p></td></tr><%}%></tbody></table></div></div><%}%><footer class="page-footer"><span class="copyright">Generated by smart-doc at ${createTime}</span><span class="footer-modification">Suggestions,contact,support and error reporting on<a href="https://gitee.com/smart-doc-team/smart-doc"target="_blank">&nbsp;Gitee</a>&nbsp;or<a href="https://github.com/shalousun/smart-doc"target="_blank">&nbsp;Github</a></span></footer></div>
</div></div><%if(isNotEmpty(consumerConfigExample)){%><div class="paragraph"><p>Consumer config</p></div><div class="listingblock"><div class="content"><pre>${consumerConfigExample}</pre></div></div><%}%></div></div><%}%><%for(api in apiDocList){%><div class="sect1"><h2 id="_${api.desc}"><a class="anchor"href="#_${api.desc}"></a><a class="link"href="#_${api.desc}">${api.order+1}.&nbsp;${api.desc}</a></h2><div class="sectionbody"><div class="paragraph"><p><strong>URI:</strong>&nbsp;${api.uri}</p></div><div class="paragraph"><p><strong>Service:</strong>&nbsp;${api.name}</p></div><div class="paragraph"><p><strong>Protocol:</strong>&nbsp;${api.protocol}</p></div><div class="paragraph"><p><strong>Author:</strong>&nbsp;${api.author}</p></div><div class="paragraph"><p><strong>Version:</strong>&nbsp;${api.version}</p></div><%for(doc in api.list){%><div class="sect2"><h3 id="_${api.order+1}_${doc.order}_${doc.desc}"><a class="anchor"href="#_${api.order+1}_${doc.order}_${doc.desc}"></a><%if(doc.deprecated){%><a class="link"href="#_${api.order+1}_${doc.order}_${doc.desc}">${api.order+1}.${doc.order}.&nbsp;<span class="line-through">${doc.desc}</span></a><%}else{%><a class="link"href="#_${api.order+1}_${doc.order}_${doc.desc}">${api.order+1}.${doc.order}.&nbsp;${doc.desc}</a><%}%></h3><div class="paragraph"><p><strong>Definition:</strong>&nbsp;${doc.escapeMethodDefinition}</p></div><div class="paragraph"><p><strong>Description:</strong>&nbsp;${doc.detail}</p></div><%if(isNotEmpty(doc.requestParams)){%><div class="paragraph"><p><strong>Invoke-parameters:</strong></p></div><table class="tableblock frame-all grid-all spread"><colgroup><col style="width: 20%;"><col style="width: 20%;"><col style="width: 20%;"><col style="width: 20%;"><col style="width: 20%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Parameter</th><th class="tableblock halign-left valign-top">Type</th><th class="tableblock halign-left valign-top">Description</th><th class="tableblock halign-left valign-top">Required</th><th class="tableblock halign-left valign-top">Since</th></tr></thead><tbody><%for(param in doc.requestParams){%><tr><td class="tableblock halign-left valign-top"><p class="tableblock">${param.field}</p></td><td class="tableblock halign-left valign-top"><p class="tableblock">${param.type}</p></td><td class="tableblock halign-left valign-top"><p class="tableblock">${param.desc}</p></td><td class="tableblock halign-left valign-top"><p class="tableblock">${param.required}</p></td><td class="tableblock halign-left valign-top"><p class="tableblock">${param.version}</p></td></tr><%}%></tbody></table><%}%><%if(isNotEmpty(doc.responseParams)){%><div class="paragraph"><p><strong>Response-fields:</strong></p></div><table class="tableblock frame-all grid-all spread"><colgroup><col style="width: 25%;"><col style="width: 25%;"><col style="width: 25%;"><col style="width: 25%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Field</th><th class="tableblock halign-left valign-top">Type</th><th class="tableblock halign-left valign-top">Description</th><th class="tableblock halign-left valign-top">Since</th></tr></thead><tbody><%for(param in doc.responseParams){%><tr><td class="tableblock halign-left valign-top"><p class="tableblock">${param.field}</p></td><td class="tableblock halign-left valign-top"><p class="tableblock">${param.type}</p></td><td class="tableblock halign-left valign-top"><p class="tableblock">${param.desc}</p></td><td class="tableblock halign-left valign-top"><p class="tableblock">${param.version}</p></td></tr><%}%></tbody></table><%}%></div><%}%></div></div><%}%><%if(isNotEmpty(errorCodeList)){%><div class="sect1"><h2 id="_error_code_list"><a class="anchor"href="#_error_code_list"></a><a class="link"href="#_error_code_list">${apiDocList.~size+2}.&nbsp;${errorListTitle}</a></h2><div class="sectionbody"><table class="tableblock frame-all grid-all spread"><colgroup><col style="width: 50%;"><col style="width: 50%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Error code</th><th class="tableblock halign-left valign-top">Description</th></tr></thead><tbody><%for(error in errorCodeList){%><tr><td class="tableblock halign-left valign-top"><p class="tableblock">${error.value}</p></td><td class="tableblock halign-left valign-top"><p class="tableblock">${error.desc}</p></td></tr><%}%></tbody></table></div></div><%}%><footer class="page-footer"><span class="copyright">Generated by smart-doc at ${createTime}</span><span class="footer-modification">Suggestions,contact,support and error reporting on<a href="https://gitee.com/smart-doc-team/smart-doc"target="_blank">&nbsp;Gitee</a>&nbsp;or<a href="https://github.com/shalousun/smart-doc"target="_blank">&nbsp;Github</a></span></footer></div>
<script src="search.js?v=${version}"></script>
<script>
$(function () {