update README and fix #19

This commit is contained in:
oppofind 2019-12-25 23:19:45 +08:00
parent f5e1d7ef8e
commit 66ef399a89
2 changed files with 45 additions and 23 deletions

View File

@ -31,21 +31,42 @@ which looks a html like generated by `asciidoctor-maven-plugin` plugin.
<dependency>
<groupId>com.github.shalousun</groupId>
<artifactId>smart-doc</artifactId>
<version>1.7.9</version>
<version>1.8.0</version>
<scope>test</scope>
</dependency>
```
#### gradle
```
testCompile 'com.github.shalousun:smart-doc:1.7.9'
testCompile 'com.github.shalousun:smart-doc:1.8.0'
```
### Create a unit test
Just running a unit test will allow Smart-doc to generate a very concise api document for you,
which is much simpler than swagger.
```
public class ApiDocTest {
@Test
public void testBuilderControllersApi() {
ApiConfig config = new ApiConfig();
//If the strict mode is set to true, Smart-doc forces that the public method in each interface in the code has a comment.
config.setStrict(true);
//When AllInOne is set to true, the document generation of all interfaces is merged into a Markdown or AsciiDoc document,
// and the error code list is output to the bottom of the document.
config.setAllInOne(true);
//Set the api document output path.
config.setOutPath("d:\\md");
//Generating Markdown documentation
ApiDocBuilder.builderControllersApi(config);
}
}
```
**Detailed use case:**
```
/**
* @author yu 2018/06/11.
*/
public class ApiDocTest {
@Test
@ -81,7 +102,6 @@ public class ApiDocTest {
ApiReqHeader.header().setName("user_uuid").setType("string").setDesc("User Uuid key")
);
//Output a list of error codes in the project, using for example:
List<ApiErrorCode> errorCodeList = new ArrayList<>();
for (ErrorCodeEnum codeEnum : ErrorCodeEnum.values()) {
@ -105,13 +125,8 @@ public class ApiDocTest {
ApiDataDictionary.dict().setTitle("Order status").setEnumClass(OrderEnum.class).setCodeField("code").setDescField("desc"),
ApiDataDictionary.dict().setTitle("Order status1").setEnumClass(OrderEnum.class).setCodeField("code").setDescField("desc")
);
long start = System.currentTimeMillis();
//Generating Markdown documentation
ApiDocBuilder.builderControllersApi(config);
long end = System.currentTimeMillis();
DateTimeUtil.printRunTime(end, start);
}
}
```

View File

@ -30,28 +30,35 @@ smart-doc使用和测试可参考[smart-doc demo](https://gitee.com/sunyureposit
<dependency>
<groupId>com.github.shalousun</groupId>
<artifactId>smart-doc</artifactId>
<version>1.7.9</version>
<version>1.8.0</version>
<scope>test</scope>
</dependency>
```
#### gradle
```
testCompile 'com.github.shalousun:smart-doc:1.7.9'
testCompile 'com.github.shalousun:smart-doc:1.8.0'
```
### Create a unit test
通过运行一个单元测试来让Smart-doc为你生成一个简洁明了的api文档
通过运行一个单元测试来让Smart-doc为你生成一个简洁明了的api文档最简单例子如下
```
@Test
public void testBuilderControllersApi() {
ApiConfig config = new ApiConfig();
//true会严格要求代码中必须有java注释首次体验可关闭正式产品推荐设置true
config.setStrict(true);
//当把AllInOne设置为true时Smart-doc将会把所有接口生成到一个Markdown、HHTML或者AsciiDoc中
config.setAllInOne(true);
//Set the api document output path.
config.setOutPath("d:\\md");
//生成Markdown文件
ApiDocBuilder.builderControllersApi(config);
}
```
**详细用例:**
```
/**
* Description:
* ApiDoc测试
*
* @author yu 2018/06/11.
*/
public class ApiDocTest {
/**
* 包括设置请求头,缺失注释的字段批量在文档生成期使用定义好的注释
*/
@Test
public void testBuilderControllersApi() {
ApiConfig config = new ApiConfig();