解析源碼文件,經過源碼及其中的註釋生成文檔信息。目前爲止註釋中使用的Tag都是Java註釋的標準Tag,後續可能會添加一些必要的自定義Tag,甚至有可能提供Tag擴展機制 —— 由使用者自定義Tag,同時自定義Tag的處理方式。html
一想到生成Java RESTful API文檔,首先就是想到Java API文檔是如何生成的,因此解析源碼的方式沒有選擇使用com.github.javaparser » javaparser-core
或者com.thoughtworks.qdox » qdox
,而是選擇JDK本身的Javadoc Tool (docs.oracle.com/en/java/jav… Tool對應的API是Javadoc API(docs.oracle.com/en/java/jav…java
因爲做者還在使用Java8,因此該項目的實現徹底是基於Javadoc API 舊版react
其中:git
Module jdk.javadoc Package com.sun.tools.javadoc This package and its contents are deprecated and may be removed in a future release. See javax.tools.ToolProvider.getSystemDocumentationTool and javax.tools.DocumentationTool for replacement functionality.github
Module jdk.javadoc Package com.sun.javadoc Note: The declarations in this package have been superseded by those in the package jdk.javadoc.doclet. For more information, see the Migration Guide in the documentation for that package.spring
@Deprecated(since="9",forRemoval=true)
public class Main extends Object 複製代碼
能夠看出,舊版Javadoc API自 Java9 已經被標記遺棄,在不久的未來將被移除,可是值得慶幸,直到最新的大版本 Java12 該API還未移除,因此使用 Java12 及之前版本的用戶能夠放心使用,後續做者會提供新版API支持。json
UI界面是基於 create-react-app 與 antd 開發的single page application —— smalldoc-antd-react-ui(github.com/liuhuagui/s…api
示例爲spring-boot項目,使用 application.yml 作爲配置文件antd
<dependency>
<groupId>com.github.liuhuagui</groupId>
<artifactId>smalldoc-spring-boot-starter</artifactId>
<version>2.3</version>
</dependency>
複製代碼
接口文檔一般在開發時使用,只須要保證文檔配置在開發環境下生效 —— spring.profiles.active=dev
數據結構
server:
port: 8080
servlet:
context-path: /my-project
spring:
profiles:
active: dev
---
spring:
profiles: dev
smalldoc:
source-paths: #額外的源碼路徑(項目的源碼路徑默認已經包含在內,不須要再添加)
- 'D:\Workspaces\myBeanProject\my-bean\src\main\java'
- 'D:\Maven\Repositories\repository\com\aliyun\aliyun-java-sdk-core\3.5.0'
packages:
- quantity.knowledgebase
- my.bean
- com.aliyuncs.auth.sts
project-name: 個人文檔
enabled: true #默認爲true
url-pattern: /smalldoc/* #默認爲/smalldoc/*
複製代碼
http://192.168.1.76:8080/my-project/smalldoc/
/** * 文章的建立,編輯,發佈,自定義 * @author KaiKang 799600902@qq.com */
@RestController
@RequestMapping("w")
public class WriteArticleController {
/** * 原創文章在編輯中保存 * @param content 內容 * @param oaCopy 原創文章副本 * @return data-草稿ID * @author KaiKang 799600902@qq.com */
@PostMapping(path = "o/save_draft",produces = {"text/plain", "application/json;charset=UTF-8"},consumes = "application/x-www-form-urlencoded")
public Result<Long> saveOriginalDraft(String content, OriginalArticleCopy oaCopy, HttpServletRequest request) {
return writeArticleService.saveOriginalDraft(content, oaCopy);
}
/** * 這只是一個測試接口 * @param content 內容 * @return 返回數據 * @author KaiKang 799600902@qq.com */
@GetMapping(path = "o/save",produces = {"text/plain", "application/json;charset=UTF-8"})
public Result<OriginalArticle> save(String content, HttpServletRequest request) {
return null;
}
}
複製代碼
http://192.168.1.76:8080/my-project/smalldoc/
my.project.controller
*Controller
的源代碼中的接口信息(規範)spring.profiles.active=*
(* 只要不是dev便可),再也不激活開發環境配置smalldoc.enabled=false
,關閉啓用test
後再進行打包,這樣連smalldoc的jar包都不會被打包進去(推薦)<dependency>
<groupId>com.github.liuhuagui</groupId>
<artifactId>smalldoc-spring-boot-starter</artifactId>
<version>2.3</version>
<scope>test</scope>
</dependency>
複製代碼
若是在使用過程當中須要幫助或者但願項目增長某些功能,歡迎issue —— github.com/liuhuagui/s…