smart-doc是一個java restful api文檔生成工具,smart-doc顛覆了傳統(tǒng)類似swagger這種大量采用注解侵入來生成文檔的實(shí)現(xiàn)方法。smart-doc完全基于接口源碼分析來生成接口文檔,完全做到零注解侵入,只需要按照java標(biāo)準(zhǔn)注釋的寫就能得到一個標(biāo)準(zhǔn)的markdown接口文檔。如果你已經(jīng)厭倦了swagger等文檔工具的注解和強(qiáng)侵入污染,那請擁抱smart-doc吧!目前smart-doc正在完善中。。。
添加依賴
<dependency>
<groupId>com.github.shalousun</groupId>
<artifactId>smart-doc</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
//嚴(yán)格模式下,會檢測javadoc,如過沒寫注釋會拋出異常
/**
* hello
*
* @author <a >dujf</a>
* @date 2018/8/31
* @since JDK1.8
*/
@RestController
@RequestMapping("/hello")
public class HelloController {
/**
* 創(chuàng)建
*
* @param user
* @return
*/
@PostMapping
public User create(User user) {
return user;
}
/**
* 查詢
*
* @param name 用戶名
* @return
*/
@GetMapping
public User getName(String name) {
return new User();
}
/**
* 修改
*
* @param name
* @return
*/
@PutMapping
public String update(String name) {
return name;
}
/**
* 刪除
*
* @param name
* @return
*/
@DeleteMapping
public String delete(String name) {
return name;
}
}
/**
* 用戶表
* @author <a >dujf</a>
* @date 2018/8/31
* @since JDK1.8
*/
public class User {
/**
* 姓名
*/
@NotNull//有此注解生成文檔require = true
private String name;
/**
* 電話
*/
private String mobile;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
}
/**
* 測試生成文檔
*/
@Test
public void testBuilderControllersApiSimple() {
ApiConfig config = new ApiConfig();
//服務(wù)地址
config.setServerUrl("http://localhost:8010");
//生成到一個文檔
config.setAllInOne(true);
//采用嚴(yán)格模式
config.isStrict();
//文檔輸出路徑
config.setOutPath("/Users/dujf/Downloads/md");
ApiDocBuilder.builderControllersApi(config);
//將生成的文檔輸出到/Users/dujf/Downloads/md目錄下,嚴(yán)格模式下api-doc會檢測Controller的接口注釋
}
生成文檔示例:

image.png

image.png
項(xiàng)目地址:https://gitee.com/athe/smart-doc-spring-boot
參考鏈接:https://github.com/shalousun/ApplicationPower/tree/master/smart-doc