比起swagger来说,smart-doc更轻量,与代码的耦合更低,不过功能比起swagger来说,也少了一些.
smart-doc的作者建议尽量使用maven插件集成,这样做生成api文档就更简单了.
下面是我集成smart-doc的过程
创建bins-smart-doc的springboot项目
在pom文件中添加
<plugin>
<groupId>com.github.shalousun</groupId>
<artifactId>smart-doc-maven-plugin</artifactId>
<version>2.2.7</version>
<configuration>
<configFile>./src/main/resources/smart-doc.json</configFile>
<projectName>smart-doc</projectName>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>html</goal>
</goals>
</execution>
</executions>
</plugin>
在resource中添加smart-doc的配置文件smart-doc.json
{
"isStrict": false,
"allInOne": true,
"outPath": "/Users/songrongbin/workspaces/apidoc",
"coverOld": true,
"createDebugPage": true,
"packageFilters": "",
"md5EncryptedHtmlName": false,
"style":"xt256",
"projectName": "smart-doc",
"skipTransientField": true,
"sortByTitle":false,
"showAuthor":true,
"requestFieldToUnderline":true,
"responseFieldToUnderline":true,
"inlineEnum":true,
"recursionLimit":7,
"allInOneDocFileName":"index.html",
"requestExample":"false",
"responseExample":"false",
"urlSuffix":"",
"displayActualType":false,
"appKey": "20201216788835306945118208",
"appToken": "c16931fa6590483fb7a4e85340fcbfef",
"secret": "W.ZyGMOB9Q0UqujVxnfi@.I#V&tUUYZR",
"openUrl": "http://localhost:8000/api",
"debugEnvName":"测试环境",
"debugEnvUrl":"http://localhost:8080",
"tornaDebug":false,
"dataDictionaries": [{
"title": "http状态码字典",
"enumClassName": "com.bins.smartdoc.common.DictEnum",
"codeField": "code",
"descField": "message"
}],
"revisionLogs": [{
"version": "1.0.0",
"revisionTime": "2021-09-26 10:30",
"status": "update",
"author": "Andybin",
"remarks": "study"
}
],
"customResponseFields": [{
"name": "code",
"desc": "响应代码",
"ownerClassName": "org.springframework.data.domain.Pageable",
"ignore":true,
"value": "00000"
}],
"customRequestFields": [{
"name":"code",
"desc":"状态码",
"ownerClassName":"com.bins.smartdoc.common.response.ResultBody",
"value":"200",
"required":true,
"ignore":false
}],
"requestHeaders": [{
"name": "token",
"type": "string",
"desc": "desc",
"value":"token请求头的值",
"required": false,
"since": "-",
"pathPatterns": "/app/test/**",
"excludePathPatterns":"/app/page/**"
},{
"name": "appkey",
"type": "string",
"desc": "desc",
"value":"appkey请求头的值",
"required": false,
"pathPatterns": "/test/add,/testConstants/1.0",
"since": "-"
}],
"requestParams": [
{
"name": "configPathParam",
"type": "string",
"desc": "desc",
"paramIn": "path",
"value":"testPath",
"required": false,
"since": "2.2.3",
"pathPatterns": "/app/test/**",
"excludePathPatterns":"/app/page/**"
}],
"apiObjectReplacements": [{
"className": "org.springframework.data.domain.Pageable",
"replacementClassName": "com.bins.smartdoc.common.request.PageDto"
}],
"apiConstants": [{
"constantsClassName": "com.bins.smartdoc.common.Constants"
}],
"responseBodyAdvice":{
"className":"com.bins.smartdoc.common.response.ResultBody"
},
"requestBodyAdvice":{
"className":"com.bins.smartdoc.common.response.ResultBody"
}
}
配置smart-doc.json,然后就可以使用smart-doc的maven插件生成api文档了,是不是很简单,不过这只是最基本的,还有很多功能需要慢慢学习.
参考代码:https://gitee.com/weitinting/bins-smart-doc.
本文暂时没有评论,来添加一个吧(●'◡'●)