2019-12-01 15:52:45 +08:00
< h1 align = "center" > Smart-Doc Project< / h1 >
2019-12-01 15:55:22 +08:00
[中文文档 ](https://github.com/shalousun/smart-doc/blob/master/README_CN.md )
2019-09-17 13:57:59 +08:00
## Introduce
2019-09-30 23:43:17 +08:00
Smart-doc is a java restful api document generation tool. Smart-doc is based on interface source code analysis to generate interface documents, and zero annotation intrusion.
You only need to write java standard comments when developing, smart-doc can help you generate a simple and clear markdown
Or a static html document. If you are tired of the numerous annotations and strong intrusion code contamination of document tools like swagger, then hug smart-doc!
2019-09-13 16:46:37 +08:00
## Features
2019-09-30 23:43:17 +08:00
- Zero annotation, zero learning cost, only need to write standard java document comments.
- Automatic derivation based on source code interface definition, powerful return structure derivation support.
- Support Spring MVC, Spring Boot, Spring Boot Web Flux (Controller mode writing).
- Supports the derivation of asynchronous interface returns such as Callable, Future, CompletableFuture.
- Support JAVA's JSR303 parameter verification specification.
- Support for automatic generation of request examples based on request parameters.
- 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).
2019-12-01 15:52:45 +08:00
- Support for generating multiple formats of documents: Markdown, HTML5, Asciidoctor,Postman Collection json.
2019-11-06 16:23:47 +08:00
- Support for exporting error codes and data dictionary codes to API documentation.
2019-09-13 16:46:37 +08:00
## Getting started
2019-10-01 00:08:21 +08:00
[Smart-doc Samples ](https://github.com/shalousun/smart-doc-demo.git )。
2019-09-13 16:46:37 +08:00
```
2019-10-01 00:08:21 +08:00
# git clone https://github.com/shalousun/smart-doc-demo.git
2019-09-13 16:46:37 +08:00
```
2019-09-30 23:43:17 +08:00
This example already provides a static html document generated in advance. You can start the Spring Boot project and then go directly to `http://localhost:8080/doc/api.html` to view the interface documentation generated by smart-doc.
Of course you can also browse `http://localhost:8080/doc/api.html` ,
which looks a html like generated by `asciidoctor-maven-plugin` plugin.
2019-11-03 16:37:21 +08:00
### Dependency
2019-11-03 16:35:47 +08:00
#### maven
2019-09-10 09:39:04 +08:00
```
< dependency >
< groupId > com.github.shalousun< / groupId >
< artifactId > smart-doc< / artifactId >
2019-12-25 23:19:45 +08:00
< version > 1.8.0< / version >
2019-09-10 09:39:04 +08:00
< scope > test< / scope >
< / dependency >
```
2019-11-03 16:35:47 +08:00
#### gradle
```
2019-12-25 23:19:45 +08:00
testCompile 'com.github.shalousun:smart-doc:1.8.0'
2019-11-03 16:35:47 +08:00
```
2019-09-13 16:46:37 +08:00
### Create a unit test
2019-09-30 23:43:17 +08:00
Just running a unit test will allow Smart-doc to generate a very concise api document for you,
which is much simpler than swagger.
2019-12-25 23:19:45 +08:00
```
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:**
2019-09-10 09:39:04 +08:00
```
public class ApiDocTest {
@Test
public void testBuilderControllersApi() {
ApiConfig config = new ApiConfig();
2019-09-30 14:47:24 +08:00
config.setServerUrl("http://localhost:8080");
2019-09-30 23:43:17 +08:00
//If the strict mode is set to true, Smart-doc forces that the public method in each interface in the code has a comment.
2019-09-10 09:39:04 +08:00
config.setStrict(true);
2019-09-30 23:43:17 +08:00
//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");
2019-11-03 15:50:54 +08:00
//since 1.7.5
//corverd old AllIneOne.md file generated by smart-doc.
config.setCoverOld(true);
//since 1.7.5
//set project name
config.setProjectName("Your project name");
2019-09-30 23:43:17 +08:00
// If you do not configure PackageFilters, it matches all controllers by default.
// Configure multiple controller paths to be separated by commas
2019-09-30 14:47:24 +08:00
config.setPackageFilters("com.power.doc.controller");
2019-09-30 23:43:17 +08:00
//Set the request header, if there is no request header, you don't need to set it.
2019-09-30 14:47:24 +08:00
config.setRequestHeaders(
2019-09-30 23:43:17 +08:00
ApiReqHeader.header().setName("access_token").setType("string")
.setDesc("Basic auth credentials").setRequired(true).setSince("v1.1.0"),
2019-09-30 14:47:24 +08:00
ApiReqHeader.header().setName("user_uuid").setType("string").setDesc("User Uuid key")
);
2019-11-03 15:50:54 +08:00
2019-09-30 23:43:17 +08:00
//Output a list of error codes in the project, using for example:
2019-09-10 09:39:04 +08:00
List< ApiErrorCode > errorCodeList = new ArrayList< >();
2019-09-30 14:47:24 +08:00
for (ErrorCodeEnum codeEnum : ErrorCodeEnum.values()) {
2019-09-10 09:39:04 +08:00
ApiErrorCode errorCode = new ApiErrorCode();
2019-09-30 14:47:24 +08:00
errorCode.setValue(codeEnum.getCode()).setDesc(codeEnum.getDesc());
2019-09-10 09:39:04 +08:00
errorCodeList.add(errorCode);
}
2019-09-30 23:43:17 +08:00
//not necessary
2019-09-10 09:39:04 +08:00
config.setErrorCodes(errorCodeList);
2019-09-30 23:43:17 +08:00
//Set the document change record,
//it is not necessary to have the document change record take effect only when setAllInOne is set to true.
2019-09-30 14:47:24 +08:00
config.setRevisionLogs(
2019-09-30 23:43:17 +08:00
RevisionLog.getLog().setRevisionTime("2018/12/15").setAuthor("chen").setRemarks("test").setStatus("create").setVersion("V1.0"),
RevisionLog.getLog().setRevisionTime("2018/12/16").setAuthor("chen2").setRemarks("test2").setStatus("update").setVersion("V2.0")
2019-09-30 14:47:24 +08:00
);
2019-11-06 15:53:13 +08:00
//since 1.7.5
//add data dictionary
config.setDataDictionaries(
2019-11-06 16:23:47 +08:00
ApiDataDictionary.dict().setTitle("Order status").setEnumClass(OrderEnum.class).setCodeField("code").setDescField("desc"),
ApiDataDictionary.dict().setTitle("Order status1").setEnumClass(OrderEnum.class).setCodeField("code").setDescField("desc")
2019-11-06 15:53:13 +08:00
);
2019-09-30 23:43:17 +08:00
//Generating Markdown documentation
2019-09-10 09:39:04 +08:00
ApiDocBuilder.builderControllersApi(config);
2019-09-30 14:47:24 +08:00
}
2019-09-10 09:39:04 +08:00
}
```
2019-09-13 16:46:37 +08:00
### Generated document example
2019-12-31 22:41:55 +08:00
#### Interface header rendering

2019-09-30 23:43:17 +08:00
#### Request parameter example rendering
2019-12-31 22:41:55 +08:00

2019-09-30 23:43:17 +08:00
#### Response parameter example renderings
2019-12-31 22:41:55 +08:00

2019-12-31 22:56:41 +08:00
## Use Maven Plugin
Smart-doc provides a maven plugin to quickly integrate into the project to generate documentation.
2019-12-31 23:01:52 +08:00
You can use the plugin instead of the unit test above. [smart-doc-maven-plugin ](https://github.com/shalousun/smart-doc-maven-plugin )
2019-10-16 21:04:48 +08:00
## Building
you can build with the following commands. (Java 1.8 is required to build the master branch)
```
2019-10-30 22:06:37 +08:00
mvn clean install -Dmaven.test.skip=true
2019-10-16 21:04:48 +08:00
```
2019-09-13 16:46:37 +08:00
## Other reference
2019-09-30 23:43:17 +08:00
- [Smart-doc manual ](https://github.com/shalousun/smart-doc/wiki )
2019-12-14 23:07:09 +08:00
## Who is using
2019-12-16 10:29:10 +08:00
These are only part of the companies using smart-doc, for reference only. If you are using smart-doc, please [add your company here ](https://github.com/shalousun/smart-doc/issues/12 ) to tell us your scenario to make smart-doc better.
2019-12-14 23:07:09 +08:00




2019-12-31 22:41:55 +08:00

2019-09-13 16:46:37 +08:00
## License
2019-09-23 21:57:46 +08:00
Smart-doc is under the Apache 2.0 license. See the [LICENSE ](https://github.com/shalousun/smart-doc/blob/master/license.txt ) file for details.
2019-09-13 16:46:37 +08:00
## Contact
2019-09-23 21:57:46 +08:00
Email: 836575280@qq.com