api-platform
项目介绍
该项目提供常用的一些工具,项目中的api-web是测试用的包,主要用来对其他项目做测试,其他各项目功能有:
api-generator是自动生成项目api文档的工具。
excel-processer是处理excel导入/导出的工具。
一、api-generator
安装教程
spring-boot集成:
添加依赖
添加依赖包
com.gitee.sergius
api-generator
2.0.0
添加配置bean:
@Bean
public ApiComponent creatApiComponent(){
return new ApiComponent()
.withScanPackage("com.gitee.sergius.smarthome.intelligent.depot.restapi")
.withYamlFilePath("D:/")
.withParseDepth(3)
.withServerHost("http://www.haiershequ.com/intelligent-community")
.build();
}
addScanPackage:添加api扫描包,可以一次添加多个包,例如 addScanPackage("com.package1","com.package2")
withYamlFilePath:配置扫描完成后是否生成存储文件,该文件存储各个api信息,如果配置了该路径,当接口方法上面的方法tag变更之后,会保留之前的接口信息,这样做主要是为了可以做接口版本控制,如果不需要,可以不配置此项,此时如果修改了接口tag,之前的版本将不做保留。
withParseDepth:请求参数和返回参数递归扫描的层数,主要用来防止当请求参数或者响应参数配置中如果有循环嵌套的时候出现死循环。
withServerHost:此参数主要用来配置页面显示的接口请求路径的主机地址部分。
添加扫描的controller包:
@ComponentScan("com.gitee.sergius.apitool.web")
spring-mvc集成:
添加依赖
添加依赖包
com.gitee.sergius
api-generator
2.0.0
添加配置bean:
@Configuration
@ComponentScan("com.gitee.sergius.apitool.web")
public class ApiConfiguration {
@Bean
public ApiComponent apiComponent(){
return new ApiComponent()
.withScanPackage("com.sandalice.api.controller")
.withServerHost("http://haiershequ.com:7531/IntelligentCommunity")
.withYamlFilePath("d:/")
.withYamlFileName("doc.yaml")
.build();
}
}
也可以在spring mvc的配置文件中通过配置项添加扫描controller。
3.添加servlet-mapping
为保证/api-doc接口请求url可以被分发,需要确认分发类DispatcherServlet能够处理/api-doc请求,该项通常在web.xml中配置,举例:
sandalice
org