处理文档BUG
This commit is contained in:
parent
71d1670417
commit
495b4c7fc9
@ -6,14 +6,17 @@ import io.swagger.models.auth.In;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.builders.ResponseBuilder;
|
||||
import springfox.documentation.service.*;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spi.service.contexts.SecurityContext;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@ -33,6 +36,12 @@ public class SwaggerConfig {
|
||||
public Docket createRestApiSystem() {
|
||||
return new Docket(DocumentationType.OAS_30)
|
||||
.enable(swaggerProperties.getActive())
|
||||
.globalResponses(HttpMethod.GET, globalResponses())
|
||||
.globalResponses(HttpMethod.POST, globalResponses())
|
||||
.globalResponses(HttpMethod.PUT, globalResponses())
|
||||
.globalResponses(HttpMethod.DELETE, globalResponses())
|
||||
.globalResponses(HttpMethod.HEAD, globalResponses())
|
||||
.globalResponses(HttpMethod.OPTIONS, globalResponses())
|
||||
.pathMapping("/")
|
||||
.groupName(ISystemConstant.API_GROUP_SYSTEM)
|
||||
.apiInfo(apiInfo())
|
||||
@ -46,6 +55,12 @@ public class SwaggerConfig {
|
||||
public Docket createRestApiResource() {
|
||||
return new Docket(DocumentationType.OAS_30)
|
||||
.enable(swaggerProperties.getActive())
|
||||
.globalResponses(HttpMethod.GET, globalResponses())
|
||||
.globalResponses(HttpMethod.POST, globalResponses())
|
||||
.globalResponses(HttpMethod.PUT, globalResponses())
|
||||
.globalResponses(HttpMethod.DELETE, globalResponses())
|
||||
.globalResponses(HttpMethod.HEAD, globalResponses())
|
||||
.globalResponses(HttpMethod.OPTIONS, globalResponses())
|
||||
.pathMapping("/")
|
||||
.groupName(ISystemConstant.API_GROUP_RESOURCE)
|
||||
.apiInfo(apiInfo())
|
||||
@ -59,6 +74,12 @@ public class SwaggerConfig {
|
||||
public Docket createRestApiApp() {
|
||||
return new Docket(DocumentationType.OAS_30)
|
||||
.enable(swaggerProperties.getActive())
|
||||
.globalResponses(HttpMethod.GET, globalResponses())
|
||||
.globalResponses(HttpMethod.POST, globalResponses())
|
||||
.globalResponses(HttpMethod.PUT, globalResponses())
|
||||
.globalResponses(HttpMethod.DELETE, globalResponses())
|
||||
.globalResponses(HttpMethod.HEAD, globalResponses())
|
||||
.globalResponses(HttpMethod.OPTIONS, globalResponses())
|
||||
.pathMapping("/")
|
||||
.groupName(ISystemConstant.API_GROUP_APP)
|
||||
.apiInfo(apiInfo())
|
||||
@ -72,6 +93,12 @@ public class SwaggerConfig {
|
||||
public Docket createRestApiWechat() {
|
||||
return new Docket(DocumentationType.OAS_30)
|
||||
.enable(swaggerProperties.getActive())
|
||||
.globalResponses(HttpMethod.GET, globalResponses())
|
||||
.globalResponses(HttpMethod.POST, globalResponses())
|
||||
.globalResponses(HttpMethod.PUT, globalResponses())
|
||||
.globalResponses(HttpMethod.DELETE, globalResponses())
|
||||
.globalResponses(HttpMethod.HEAD, globalResponses())
|
||||
.globalResponses(HttpMethod.OPTIONS, globalResponses())
|
||||
.pathMapping("/")
|
||||
.groupName(ISystemConstant.API_GROUP_WECHAT)
|
||||
.apiInfo(apiInfo())
|
||||
@ -85,6 +112,12 @@ public class SwaggerConfig {
|
||||
public Docket createRestApiWechatMiniapp() {
|
||||
return new Docket(DocumentationType.OAS_30)
|
||||
.enable(swaggerProperties.getActive())
|
||||
.globalResponses(HttpMethod.GET, globalResponses())
|
||||
.globalResponses(HttpMethod.POST, globalResponses())
|
||||
.globalResponses(HttpMethod.PUT, globalResponses())
|
||||
.globalResponses(HttpMethod.DELETE, globalResponses())
|
||||
.globalResponses(HttpMethod.HEAD, globalResponses())
|
||||
.globalResponses(HttpMethod.OPTIONS, globalResponses())
|
||||
.pathMapping("/")
|
||||
.groupName(ISystemConstant.API_GROUP_WECHAT_MINI_APP)
|
||||
.apiInfo(apiInfo())
|
||||
@ -94,6 +127,23 @@ public class SwaggerConfig {
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 全局响应
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private List<Response> globalResponses() {
|
||||
List<Response> responses = new ArrayList<>();
|
||||
responses.add(new ResponseBuilder().code("200").description("成功").build());
|
||||
responses.add(new ResponseBuilder().code("400").description("请求失败").build());
|
||||
responses.add(new ResponseBuilder().code("401").description("认证失败").build());
|
||||
responses.add(new ResponseBuilder().code("403").description("禁止访问").build());
|
||||
responses.add(new ResponseBuilder().code("404").description("未找到").build());
|
||||
responses.add(new ResponseBuilder().code("500").description("系统错误").build());
|
||||
return responses;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置授权信息
|
||||
*/
|
||||
|
@ -252,7 +252,7 @@ public class ApiInfoServiceImpl extends DefaultBaseService implements IApiInfoSe
|
||||
Map<String, Object> requestParameter = new HashMap<>();
|
||||
requestParameter.put("class", parameter.getClass());
|
||||
requestParameter.put("name", parameter.getName());
|
||||
requestParameter.put("description", parameter.getDescription());
|
||||
requestParameter.put("description", StringUtils.isBlank(parameter.getDescription()) ? "" : parameter.getDescription());
|
||||
String type = StringUtils.isBlank(parameter.getPattern()) ? "string" : parameter.getPattern();
|
||||
requestParameter.put("in", parameter.getIn());
|
||||
if (StringUtils.equals(parameter.getIn(), "body")) {
|
||||
@ -266,14 +266,13 @@ public class ApiInfoServiceImpl extends DefaultBaseService implements IApiInfoSe
|
||||
if (parameter instanceof BodyParameter) {
|
||||
BodyParameter bodyParameter = (BodyParameter) parameter;
|
||||
Model schema = bodyParameter.getSchema();
|
||||
if (schema == null) {
|
||||
continue;
|
||||
}
|
||||
requestParameter.put("schemaClass", schema.getClass());
|
||||
if (schema instanceof RefModel) {
|
||||
RefModel refModel = (RefModel) schema;
|
||||
ref = refModel.get$ref();
|
||||
simpleRef = refModel.getSimpleRef();
|
||||
if (schema != null) {
|
||||
requestParameter.put("schemaClass", schema.getClass());
|
||||
if (schema instanceof RefModel) {
|
||||
RefModel refModel = (RefModel) schema;
|
||||
ref = refModel.get$ref();
|
||||
simpleRef = refModel.getSimpleRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
requestParameter.put("ref", ref);
|
||||
|
Loading…
Reference in New Issue
Block a user