apidoc的maven外掛,自動生成apidoc.json
阿新 • • 發佈:2019-01-28
外掛是用apidoc外掛生成文件的,具體使用方式可檢視官網:http://apidocjs.com/
該外掛不會直接生成APIDOC文件,只會自動生成apidoc.json檔案,需要執行apidoc
命令才可以生成
apidoc.json檔案會生成在專案根目錄apidoc資料夾下
下載依賴包
git clone https://gitee.com/qianxunclub/qianxunclub-maven-plugin.git
cd qianxunclub-maven-plugin
mvn clean install
編輯pom.xml,引入maven plugin
在專案的pom檔案中引入以下:
<plugin>
<groupId>com.qianxunclub</groupId>
<artifactId>qianxunclub-plugin-apidoc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>apidoc</goal>
</goals>
</execution>
</executions>
</plugin>
在properties
定義API的生成規範:
<properties>
<apidoc.skip>false/</apidoc.skip>
<apidoc.gen>false</apidoc.gen>
<apidoc.url>http://ip:port/</apidoc.url>
<apidoc.sampleUrl >http://ip:port/</apidoc.sampleUrl>
</properties>
apidoc.skip:編譯程式碼是否跳過生成apidoc.json
apidoc.gen:是否覆蓋更新apidoc.json
apidoc.url:例項介面字首
apidoc.sampleUrl:生成測試方法的請求地址
開始生成
執行命令:
mvn clean package
可以新增以下引數:
mvn clean package -Dapidoc.skip=true
-Dapidoc.skip=true:編譯程式碼是否跳過生成apidoc.json
-Dapidoc.gen=true:是否覆蓋更新apidoc.json
-Dapidoc.url=xxx:例項介面字首
-Dapidoc.sampleUrl=xxx:生成測試方法的請求地址
如果出現以下字樣,說明生成完成:
apidoc.json完成
生成api文件
在專案跟目錄執行:
apidoc -i apidoc/ -o API文件存放目錄/
開啟API文件存放目錄中的index.html
即可檢視文件。