Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
shalousun committed Nov 6, 2019
1 parent bc5dd88 commit 85789c8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 67 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Or a static html document. If you are tired of the numerous annotations and stro
- Support for generating json return value examples.
- Support for loading source code from outside the project to generate field comments (including the sources jar package).
- Support for generating multiple formats of documents: Markdown, HTML5, Asciidoctor.
- Support for exporting error codes and data dictionary codes to API documentation.
## Getting started
[Smart-doc Samples](https://github.com/shalousun/smart-doc-demo.git)
```
Expand Down Expand Up @@ -99,8 +100,8 @@ public class ApiDocTest {
//since 1.7.5
//add data dictionary
config.setDataDictionaries(
ApiDataDictionary.dict().setTitle("Order status").setEnumClass(OrderEnum.class).setValueField("code").setDescField("desc"),
ApiDataDictionary.dict().setTitle("Order status1").setEnumClass(OrderEnum.class).setValueField("code").setDescField("desc")
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();
Expand Down
5 changes: 3 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ smart-doc完全基于接口源码分析来生成接口文档,完全做到零
- 支持生成多种格式文档:Markdown、HTML5、Asciidoctor。
- 轻易实现在Spring Boot服务上在线查看静态HTML5 api文档。
- 开放文档数据,可自由实现接入文档管理系统。
- 支持导出错误码和定义在代码中的各种字典码到接口文档。
## Getting started
smart-doc使用和测试可参考[smart-doc demo](https://gitee.com/sunyurepository/api-doc-test.git)
```
Expand Down Expand Up @@ -113,8 +114,8 @@ public class ApiDocTest {
//since 1.7.5
//文档添加数据字典
config.setDataDictionaries(
ApiDataDictionary.dict().setTitle("订单状态").setEnumClass(OrderEnum.class).setValueField("code").setDescField("desc"),
ApiDataDictionary.dict().setTitle("订单状态1").setEnumClass(OrderEnum.class).setValueField("code").setDescField("desc")
ApiDataDictionary.dict().setTitle("订单状态").setEnumClass(OrderEnum.class).setCodeField("code").setDescField("desc"),
ApiDataDictionary.dict().setTitle("订单状态1").setEnumClass(OrderEnum.class).setCodeField("code").setDescField("desc")
);
Expand Down
6 changes: 4 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,16 @@
5. 优化AllInOne的markdown展示,生成时带上自动产生的序号。

#### 版本号:1.7.5
- 更新日期:待定
- 更新日期:2019-11-06
- 更新内容:
1. 优化文档中错误列表的标题,可根据语言环境变化显示中文或因为。
2. 解决项目外jar中内部类生成文档错误的bug。
3. 支持环形依赖分析。只要你敢写!
4. 修改使用SpringMvc或者SpringBoot上传时接口的Content-Type显示错误。
5. 支持设置项目作为markdown的一级标题。
6. 修改方法注释相同引起的html链接跳转错误
6. 修改方法注释相同引起的html链接跳转错误。
7. 添加生成AllInOne的覆盖配置项,默认自动加版本号不覆盖。
8. 新增枚举字典码导出到文档的功能。



Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public List<ApiDocDict> buildDictionary(ApiConfig config) {
}
List<DataDict> dataDictList = new ArrayList<>();
Object[] objects = clzz.getEnumConstants();
String valueMethodName = "get" + StringUtil.firstToUpperCase(apiDataDictionary.getValueField());
String valueMethodName = "get" + StringUtil.firstToUpperCase(apiDataDictionary.getCodeField());
String descMethodName = "get" + StringUtil.firstToUpperCase(apiDataDictionary.getDescField());
Method valueMethod = clzz.getMethod(valueMethodName);
Method descMethod = clzz.getMethod(descMethodName);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/power/doc/model/ApiDataDictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public class ApiDataDictionary {
private String enumClassName;

/**
* value field
* code field
*/
private String valueField;
private String codeField;

/**
* description field
Expand Down Expand Up @@ -53,12 +53,12 @@ public ApiDataDictionary setEnumClass(Class enumClass) {
return this;
}

public String getValueField() {
return valueField;
public String getCodeField() {
return codeField;
}

public ApiDataDictionary setValueField(String valueField) {
this.valueField = valueField;
public ApiDataDictionary setCodeField(String codeField) {
this.codeField = codeField;
return this;
}

Expand Down
55 changes: 1 addition & 54 deletions src/test/java/com/power/doc/ApiDocTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,6 @@
*/
public class ApiDocTest {

/**
* 简单型接口,不需要指定请求头,并且项目是maven的.
*/
/*
@Test
public void testBuilderControllersApiSimple() {
//将生成的文档输出到d:\md目录下,严格模式下api-doc会检测Controller的接口注释
ApiDocBuilder.builderControllersApi("d:\\md",true);
}
*/

/**
* 包括设置请求头,缺失注释的字段批量在文档生成期使用定义好的注释
*/
Expand All @@ -53,7 +42,7 @@ public void testBuilderControllersApi() {
//SourcePath.path().setDesc("加载项目外代码").setPath("E:\\ApplicationPower\\ApplicationPower\\Common-util\\src\\main\\java")
);
config.setDataDictionaries(
ApiDataDictionary.dict().setTitle("订单字典").setEnumClass(OrderEnum.class).setValueField("code").setDescField("desc")
ApiDataDictionary.dict().setTitle("订单字典").setEnumClass(OrderEnum.class).setCodeField("code").setDescField("desc")
);
//设置请求头,如果没有请求头,可以不用设置
/* config.setRequestHeaders(
Expand All @@ -76,48 +65,6 @@ public void testBuilderControllersApi() {
RevisionLog.getLog().setRevisionTime("2018/12/16").setAuthor("chen2").setRemarks("测试2").setStatus("修改").setVersion("V2.0")
);

List<ApiDataDictionary> apiDataDictionaryList = config.getDataDictionaries();
try {
List<ApiDocDict> apiDocDictList = new ArrayList<>();//模板中遍历这个字典表生成字典文档
int order = 0;
for (ApiDataDictionary apiDataDictionary : apiDataDictionaryList) {
System.out.println("dictionary:" + apiDataDictionary.getTitle());
order++;
ApiDocDict apiDocDict = new ApiDocDict();
apiDocDict.setOrder(order);//设置方便在文档中的小结顺序
apiDocDict.setTitle(apiDataDictionary.getTitle());
Class<?> clzz = apiDataDictionary.getEnumClass();
if (Objects.isNull(clzz)) {
if (StringUtil.isEmpty(apiDataDictionary.getEnumClassName())) {
throw new RuntimeException(" enum class name can't be null.");
}
//如果没有设置class那么检查是否设置了字符串类型的class name
clzz = Class.forName(apiDataDictionary.getEnumClassName());
}
if (!clzz.isEnum()) {
throw new RuntimeException(clzz.getCanonicalName() + " is not an enum class.");
}
List<DataDict> dataDictList = new ArrayList<>();
Object[] objects = clzz.getEnumConstants();
String valueMethodName = "get" + StringUtil.firstToUpperCase(apiDataDictionary.getValueField());
String descMethodName = "get" + StringUtil.firstToUpperCase(apiDataDictionary.getDescField());
Method valueMethod = clzz.getMethod(valueMethodName);
Method descMethod = clzz.getMethod(descMethodName);
for (Object object : objects) {
Object val = valueMethod.invoke(object);
Object desc = descMethod.invoke(object);
DataDict dataDict = new DataDict();
dataDict.setDesc(desc.toString());
dataDict.setValue(val.toString());
dataDictList.add(dataDict);
System.out.println("enum value=" + val + "desc=" + desc);
}
apiDocDict.setDataDictList(dataDictList);
apiDocDictList.add(apiDocDict);
}
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | ClassNotFoundException e) {
e.fillInStackTrace();
}


long start = System.currentTimeMillis();
Expand Down

0 comments on commit 85789c8

Please sign in to comment.