Dataway整合Swagger
一、利用整合好的Spring boot-dataway项目,不清楚或是有疑问的地方请看《Dataway整合Spring Boot》
二、添加项目依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
三、新建启用Swagger类如下
@EnableSwagger2
@Configuration
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)//
.apiInfo(apiInfo())//
.select()//
.apis(RequestHandlerSelectors.basePackage("com.norman.hasor"))//
.paths(PathSelectors.any())//
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()//
.title("Spring Boot整合Dataway+Swagger2构建RESTful APIs")//
.description("初次整合DS构建API")//
.termsOfServiceUrl("#")//
.contact("lzl").version("1.0")//
.build();
}
}
四、新建类利用Swagger整合Dataway接口如下
@Component
@Primary
public class SwaggerProvider implements SwaggerResourcesProvider{
@Override
public List<SwaggerResource> get() {
List<SwaggerResource> resources = new ArrayList<>();
resources.add(swaggerResource("应用接口", "/v2/api-docs", "1.0"));
resources.add(swaggerResource("Dataway接口", "/interface-ui/api/docs/swagger2.json", "1.0"));
return resources;
}
private SwaggerResource swaggerResource(String name, String location, String version) {
SwaggerResource swaggerResource = new SwaggerResource();
swaggerResource.setName(name);
swaggerResource.setLocation(location);
swaggerResource.setSwaggerVersion(version);
return swaggerResource;
}
}
五、启动项目后访问http://127.0.0.1:8080/swagger-ui.html#/,访问结果如下,点击对应的接口测试数据与原链接http://localhost:8080/interface-ui/#/测试结果一致