README.org
September 9, 2024 · View on GitHub
English Readme | [[README-cn.org][中文说明]]
[[https://github.com/liuanxin/api-document-example-en][Example project(spring boot 2)]]
[[https://liuanxin.github.io/api-info-en.html][Document example]] | [[https://liuanxin.github.io/api-info-en-example.html][Document example for Front-Back-end interaction]]
** Comment
People who have maintained the project should have experience. If the api documentation is written separately (org-mode, markdown, rap or even word), as the project cycle progresses, the gap between the interface document and the real code will come the farther away.
This document collection application has appeared because some of the details based on swagger are not so good, For example, the map cannot be parsed, the circular reference cannot be parsed, and the entry and exit parameters are poorly sorted. view desc need to be swtich(comments should be where the examples are, not together is a very bad experience).
** Usage
add maven
#+BEGIN_SRC xml
add config for this #+BEGIN_SRC java @Configuration @EnableApiInfo public class ApiInfoConfig {
// can be set in different profile, such as:
// application.yml => online: false
// application-test.yml => online: false
// application-prod.yml => online: true
@Value("${online:false}")
private boolean online;
@Bean
public DocumentCopyright apiCopyright() {
return new DocumentCopyright("title", "team", "version", "copyright")
// not collect if true, default is false.
.setOnline(online)
// // if some api can't use @ApiIgnore, set this(url|method, method can be ignore)
// .setIgnoreUrlSet(Sets.newHashSet("/user*", "/product/info|post"))
// // if class or method has @ApiResponses, use that
// .setGlobalResponse(Arrays.asList(
// new DocumentResponse(400, "param error"),
// new DocumentResponse(500, "request error").setResponse(XXX.class) // see @ApiReturnType
// ))
// // current config will be generated in the parameters of each api, if only want to use
// // on a specific api, or set this global config but want to ignore on a specific api,
// // use @ApiTokens annotation
// .setGlobalTokens(Arrays.asList(
// DocumentParam.buildToken("x-token", "oauth info", "abc", ParamType.Header).setHasTextarea("1"),
// DocumentParam.buildToken("x-version", "api version", "1.0.0", ParamType.Query).setRequired("1")
// ))
// // field comment is output in the return example.
// // default is true. set to false will be listed separately.
// .setCommentInReturnExample(false)
// // used in multi-document collection, merged items and output, default is false
// // If true, please ensure that the global response description
// // and global token of all items are consistent.
// // Duplication and appending together (current practice) will cause documentation errors.
// // If false, multiple documents will be requested on the page,
// // please ensure that all projects have cors turned on,
// // otherwise it will be inaccessible due to cross-domain issues
// .setProjectMerge(true)
// // Collecting document for other projects
// .setProjectMap(new LinkedHashMap<String, String>() {{
// // key: name, value: project address
// put("user", "http://ip:port/user");
// put("product", "http://ip:port/product");
// }})
;
}
} #+END_SRC
Then mark the corresponding annotations in the corresponding controller layer(only collect the documents related to
@RestController or @ResponseBody related classes and interfaces, If the result of the method is List,
Set or Map will be processed by ArrayList, HashSet and HashMap),
ResponseEntity or Callable or DeferredResult or WebAsyncTask will handle the generic type it defines
(it will not be resolved without setting).
PS: You can refer to the global processing of [[https://github.com/liuanxin/api-document-example-en][example project(spring boot 2)]].
For generics, be sure to use certain types, such as