天天看點

spring boot + spring rest doc + junit5 實作文檔

現在文檔大部分都是用swagger來生成的,但是springboot官網也提供了 spring rest doc 元件用于生成文檔,因為java項目基本上都是用spring boot來建立的,是以個人傾向于spring rest doc.

spring rest doc 主要是基于unit單元測試實作的,添加依賴

添加asciidoctor配置,這塊主要是配置生成snippets檔案,

添加單元測試

看紅色的document方法,這個會在打包的時候這個路徑build\generated-snippets\contract生成contract的snippets片段

controller類是

執行指令前 我們需要建立模闆檔案,在這個目錄下src/docs/asciidoc/contract.adoc建立contract.adoc檔案

然後運作下面這個指令,asciidoctor會根據上面建立的contract.adoc生成html檔案,通過include引入adoc即可include::{snippets}/contract/http-request.adoc[].詳情參閱官方文檔

spring boot + spring rest doc + junit5 實作文檔

我們就可以發現 

\build\asciidoc\html5 在這個目錄下生成了 html檔案

spring boot + spring rest doc + junit5 實作文檔

 打開後就顯示出了文檔界面,需要寫出漂亮的界面還要學習asciidoc文檔的文法

spring boot + spring rest doc + junit5 實作文檔

繼續閱讀