swagger添加分组
This commit is contained in:
parent
165a05c349
commit
78c32e0621
@ -1,5 +1,6 @@
|
||||
package com.cm.common.config;
|
||||
|
||||
import com.cm.common.constants.ISystemConstant;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -37,13 +38,17 @@ public class SwaggerConfig {
|
||||
@Value("${swagger.swagger-base-package}")
|
||||
private String swaggerBasePackage = "com.cm";
|
||||
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
private List<ResponseMessage> responseMessageList() {
|
||||
List<ResponseMessage> responseMessageList = new ArrayList<>();
|
||||
responseMessageList.add(new ResponseMessageBuilder().code(400).message("请求失败").build());
|
||||
responseMessageList.add(new ResponseMessageBuilder().code(404).message("请求不存在").build());
|
||||
responseMessageList.add(new ResponseMessageBuilder().code(503).message("服务不可用").build());
|
||||
return responseMessageList;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Docket createRestGlobalApi() {
|
||||
List<ResponseMessage> responseMessageList = responseMessageList();
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.globalResponseMessage(RequestMethod.POST, responseMessageList)
|
||||
.globalResponseMessage(RequestMethod.DELETE, responseMessageList)
|
||||
@ -56,6 +61,86 @@ public class SwaggerConfig {
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Docket createRestApiSystem() {
|
||||
List<ResponseMessage> responseMessageList = responseMessageList();
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.globalResponseMessage(RequestMethod.POST, responseMessageList)
|
||||
.globalResponseMessage(RequestMethod.DELETE, responseMessageList)
|
||||
.globalResponseMessage(RequestMethod.PUT, responseMessageList)
|
||||
.globalResponseMessage(RequestMethod.GET, responseMessageList)
|
||||
.groupName(ISystemConstant.API_GROUP_SYSTEM)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage(swaggerBasePackage))
|
||||
.paths(PathSelectors.ant("/api/**"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Docket createRestApiResource() {
|
||||
List<ResponseMessage> responseMessageList = responseMessageList();
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.globalResponseMessage(RequestMethod.POST, responseMessageList)
|
||||
.globalResponseMessage(RequestMethod.DELETE, responseMessageList)
|
||||
.globalResponseMessage(RequestMethod.PUT, responseMessageList)
|
||||
.globalResponseMessage(RequestMethod.GET, responseMessageList)
|
||||
.groupName(ISystemConstant.API_GROUP_RESOURCE)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage(swaggerBasePackage))
|
||||
.paths(PathSelectors.ant("/resource/**"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Docket createRestApiApp() {
|
||||
List<ResponseMessage> responseMessageList = responseMessageList();
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.globalResponseMessage(RequestMethod.POST, responseMessageList)
|
||||
.globalResponseMessage(RequestMethod.DELETE, responseMessageList)
|
||||
.globalResponseMessage(RequestMethod.PUT, responseMessageList)
|
||||
.globalResponseMessage(RequestMethod.GET, responseMessageList)
|
||||
.groupName(ISystemConstant.API_GROUP_APP)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage(swaggerBasePackage))
|
||||
.paths(PathSelectors.ant("/app/**"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Docket createRestApiRoute() {
|
||||
List<ResponseMessage> responseMessageList = responseMessageList();
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.globalResponseMessage(RequestMethod.POST, responseMessageList)
|
||||
.globalResponseMessage(RequestMethod.DELETE, responseMessageList)
|
||||
.globalResponseMessage(RequestMethod.PUT, responseMessageList)
|
||||
.globalResponseMessage(RequestMethod.GET, responseMessageList)
|
||||
.groupName(ISystemConstant.API_GROUP_ROUTE)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage(swaggerBasePackage))
|
||||
.paths(PathSelectors.ant("/route/**"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Docket createRestApiWechat() {
|
||||
List<ResponseMessage> responseMessageList = responseMessageList();
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.globalResponseMessage(RequestMethod.POST, responseMessageList)
|
||||
.globalResponseMessage(RequestMethod.DELETE, responseMessageList)
|
||||
.globalResponseMessage(RequestMethod.PUT, responseMessageList)
|
||||
.globalResponseMessage(RequestMethod.GET, responseMessageList)
|
||||
.groupName(ISystemConstant.API_GROUP_WECHAT)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage(swaggerBasePackage))
|
||||
.paths(PathSelectors.ant("/wechat/**"))
|
||||
.build();
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title(swaggerTitle)
|
||||
|
@ -32,6 +32,26 @@ public interface ISystemConstant {
|
||||
* 微信接口前缀
|
||||
*/
|
||||
String API_TAGS_WECHAT_PREFIX = "微信接口-";
|
||||
/**
|
||||
* 系统接口分组
|
||||
*/
|
||||
String API_GROUP_SYSTEM = "SYSTEM";
|
||||
/**
|
||||
* 资源接口分组
|
||||
*/
|
||||
String API_GROUP_RESOURCE = "RESOURCE";
|
||||
/**
|
||||
* APP接口分组
|
||||
*/
|
||||
String API_GROUP_APP = "APP";
|
||||
/**
|
||||
* 路由接口分组
|
||||
*/
|
||||
String API_GROUP_ROUTE = "ROUTE";
|
||||
/**
|
||||
* 微信接口分组
|
||||
*/
|
||||
String API_GROUP_WECHAT = "WECHAT";
|
||||
/**
|
||||
* api前缀
|
||||
*/
|
||||
@ -140,4 +160,5 @@ public interface ISystemConstant {
|
||||
* session的AccessToken
|
||||
*/
|
||||
String SESSION_WECHAT_ACCESS_TOKEN = "SESSION_WECHAT_ACCESS_TOKEN";
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user