一個非侵入的api編譯、收集、Rest文檔生成工具。工具通過分析代碼和注釋,獲取文檔信息,生成RestDoc文檔
前言
程序員一直以來都有一個煩惱,只想寫代碼,不想寫文檔。代碼就表達了我的思想和靈魂。
Python提出了一個方案,叫docstring,來試圖解決這個問題。即編寫代碼,同時也能寫出文檔,保持代碼和文檔的一致。docstring說白了就是一堆代碼中的注釋。Python的docstring可以通過help函數直接輸出一份有格式的文檔,本工具的思想與此類似。
代碼即文檔
Apigcc是一個非侵入的RestDoc文檔生成工具。工具通過分析代碼和注釋,獲取文檔信息,生成RestDoc文檔。
有這樣一段代碼
/** * 歡迎使用Apigcc * @index 1 */ @RestController public class HelloController { /** * 示例接口 * @param name 名稱 * @return */ @RequestMapping("/greeting") public HelloDTO greeting(@RequestParam(defaultValue="apigcc") String name) { return new HelloDTO("hello "+name); } }
生成文檔效果
使用方式
apiggs-maven-plugin
easy use apigcc with maven
install
<plugin> <groupId>com.github.apiggs</groupId> <artifactId>apiggs-maven-plugin</artifactId> <version><!-- 替換為上方版本號 --></version> <executions> <execution> <phase>compile</phase> <goals> <goal>apiggs</goal> </goals> </execution> </executions> <configuration> <!-- options in there --> </configuration> </plugin>
when you compile source code, apiggs will build rest doc.
options
- id 項目id,生成id.html文件
- title 文檔標題
- description 文檔描述
- production 輸出文件夾,默認為 apiggs
- out 輸出目錄,默認為 target
- source 源碼目錄
- dependency 源碼依賴的代碼目錄,以逗號隔開
- jar 源碼依賴的jar包目錄,以逗號隔開
- ignore 忽略某些類型
- version 文檔版本號
執行方法:
查看API文檔:
另外,也可以放入容器遠程訪問,方法如下:
運行項目
gradlew build cd service\build\libs java -jar apigcc-hub-{version}.jar
瀏覽器訪問 http://127.0.0.1:8080
詳情請參考:apigcc