mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2025-12-19 02:02:50 +00:00
完善openapi,移除过期sql
This commit is contained in:
parent
ee382c0a5b
commit
2b0bedd263
@ -180,7 +180,7 @@ public class ShiroConfig {
|
||||
// 企业微信证书排除
|
||||
filterChainDefinitionMap.put("/WW_verify*", "anon");
|
||||
|
||||
filterChainDefinitionMap.put("/openapi/**", "anon");
|
||||
filterChainDefinitionMap.put("/openapi/call/**", "anon");
|
||||
|
||||
// 添加自己的过滤器并且取名为jwt
|
||||
Map<String, Filter> filterMap = new HashMap<String, Filter>(1);
|
||||
|
||||
@ -10,21 +10,30 @@ import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.constant.CommonConstant;
|
||||
import org.jeecg.common.system.base.controller.JeecgController;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.system.util.JwtUtil;
|
||||
import org.jeecg.modules.openapi.entity.OpenApi;
|
||||
import org.jeecg.modules.openapi.entity.OpenApiAuth;
|
||||
import org.jeecg.modules.openapi.entity.OpenApiHeader;
|
||||
import org.jeecg.modules.openapi.entity.OpenApiParam;
|
||||
import org.jeecg.modules.openapi.generator.PathGenerator;
|
||||
import org.jeecg.modules.openapi.service.OpenApiAuthService;
|
||||
import org.jeecg.modules.openapi.service.OpenApiHeaderService;
|
||||
import org.jeecg.modules.openapi.service.OpenApiParamService;
|
||||
import org.jeecg.modules.openapi.service.OpenApiService;
|
||||
import org.jeecg.modules.system.entity.SysUser;
|
||||
import org.jeecg.modules.system.service.ISysUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import springfox.documentation.schema.*;
|
||||
import springfox.documentation.schema.Model;
|
||||
import springfox.documentation.schema.ModelProperty;
|
||||
import springfox.documentation.schema.ModelRef;
|
||||
import springfox.documentation.schema.ModelReference;
|
||||
import springfox.documentation.service.*;
|
||||
import springfox.documentation.spring.web.DocumentationCache;
|
||||
|
||||
@ -36,7 +45,7 @@ import java.util.*;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/openapi")
|
||||
public class OpenApiController extends JeecgController<OpenApi, OpenApiService> {
|
||||
public class OpenApiController extends JeecgController<OpenApi, OpenApiService> implements CommandLineRunner {
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
@ -48,6 +57,10 @@ public class OpenApiController extends JeecgController<OpenApi, OpenApiService>
|
||||
private DocumentationCache documentationCache;
|
||||
@Autowired
|
||||
private TypeResolver typeResolver;
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
@Autowired
|
||||
private OpenApiAuthService openApiAuthService;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
@ -177,6 +190,12 @@ public class OpenApiController extends JeecgController<OpenApi, OpenApiService>
|
||||
httpHeaders.put(header.getHeaderKey(), Lists.newArrayList(request.getHeader(header.getHeaderKey())));
|
||||
}
|
||||
|
||||
String appkey = request.getHeader("appkey");
|
||||
OpenApiAuth openApiAuth = openApiAuthService.getByAppkey(appkey);
|
||||
SysUser systemUser = sysUserService.getById(openApiAuth.getSystemUserId());
|
||||
String token = JwtUtil.sign(systemUser.getUsername(), systemUser.getPassword());
|
||||
httpHeaders.put("X-Access-Token", Lists.newArrayList(token));
|
||||
|
||||
HttpEntity<String> httpEntity = new HttpEntity<>(json, httpHeaders);
|
||||
|
||||
return restTemplate.exchange(url, HttpMethod.resolve(method), httpEntity, Result.class, request.getParameterMap()).getBody();
|
||||
@ -218,8 +237,8 @@ public class OpenApiController extends JeecgController<OpenApi, OpenApiService>
|
||||
List<ModelReference> subTypes = new ArrayList<>();
|
||||
subTypes.add(stringModelRef);
|
||||
|
||||
Model bodyModel = new Model("path_body", "body", mapResolvedType, "java.util.HashMap", propertyMap, "请求体结构", "", "", subTypes, null, null);
|
||||
ModelRef bodyRef = new ModelRef("bodyModel", "bodyModel", null, null, "path_body");
|
||||
Model bodyModel = new Model("path_body", "bodyModel", mapResolvedType, "java.util.HashMap", propertyMap, "请求体结构", "", "", subTypes, null, null);
|
||||
ModelRef bodyRef = new ModelRef("bodyModel", "path_body", null, null,true, "path_body");
|
||||
|
||||
Set<ResponseMessage> responseMessages = documentation.getApiListings().get("login-controller").get(0).getApis().get(2).getOperations().get(0).getResponseMessages();
|
||||
|
||||
@ -229,7 +248,7 @@ public class OpenApiController extends JeecgController<OpenApi, OpenApiService>
|
||||
// path-->请求参数的获取:@PathVariable()
|
||||
// body-->请求参数的获取:@RequestBody()
|
||||
// form(不常用)
|
||||
Parameter body = new Parameter("body",
|
||||
Parameter body = new Parameter("bodyModel",
|
||||
"请求体",
|
||||
"",
|
||||
true,
|
||||
@ -329,7 +348,11 @@ public class OpenApiController extends JeecgController<OpenApi, OpenApiService>
|
||||
return r;
|
||||
}
|
||||
|
||||
public void resetOpenapiSwagger() {
|
||||
/**
|
||||
* resetOpenapiSwagger
|
||||
*/
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
List<OpenApi> openapis = service.list();
|
||||
Documentation documentation = documentationCache.documentationByGroup("default");
|
||||
List<ApiListing> apis = new ArrayList<>();
|
||||
@ -418,11 +441,11 @@ public class OpenApiController extends JeecgController<OpenApi, OpenApiService>
|
||||
parameters.add(parameter);
|
||||
}
|
||||
|
||||
Operation operation = new Operation(HttpMethod.resolve("GET"),
|
||||
"模拟第一个openapi接口",
|
||||
"模拟第一个openapi接口",
|
||||
Operation operation = new Operation(HttpMethod.resolve(openapi.getRequestMethod()),
|
||||
openapi.getName(),
|
||||
openapi.getName(),
|
||||
modelRef,
|
||||
"abcUsingGET",
|
||||
openapi.getName()+"Using"+openapi.getRequestMethod(),
|
||||
0, tags, produces, consumes,
|
||||
new LinkedHashSet<>(),
|
||||
new ArrayList<>(),
|
||||
@ -436,7 +459,7 @@ public class OpenApiController extends JeecgController<OpenApi, OpenApiService>
|
||||
operations.add(operation);
|
||||
|
||||
ApiDescription apiDescription = new ApiDescription("openapi",
|
||||
"/jeecg-boot/openapi/call/abc", "openapi", operations, false);
|
||||
"/jeecg-boot/openapi/call/"+openapi.getRequestUrl(), openapi.getName(), operations, false);
|
||||
|
||||
List<ApiDescription> apiList = new ArrayList<>();
|
||||
apiList.add(apiDescription);
|
||||
@ -446,7 +469,7 @@ public class OpenApiController extends JeecgController<OpenApi, OpenApiService>
|
||||
|
||||
ApiListing api = new ApiListing("1.0",
|
||||
"/",
|
||||
"/openapi/call/abc",
|
||||
"/openapi/call/"+openapi.getRequestUrl(),
|
||||
produces, consumes,
|
||||
"", new HashSet<>(), new ArrayList<>(), apiList, responseModel, "abc", 0, apiTags);
|
||||
|
||||
|
||||
@ -41,6 +41,11 @@ public class OpenApiAuth implements Serializable {
|
||||
*/
|
||||
private String sk;
|
||||
|
||||
/**
|
||||
* 系统用户ID
|
||||
*/
|
||||
private String systemUserId;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
|
||||
@ -1 +0,0 @@
|
||||
INSERT INTO `open_api` (`id`, `name`, `request_method`, `request_url`, `black_list`, `body`, `origin_url`, `status`, `del_flag`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES ('1870486348755324929', '示例接口', 'GET', 'UrTk8CTk', NULL, NULL, 'http://localhost:8080/jeecg-boot/openapi/demo/index', 1, 0, NULL, '2024-12-21 23:07:52', NULL, NULL);
|
||||
@ -1 +0,0 @@
|
||||
INSERT INTO `open_api_auth` (`id`, `name`, `ak`, `sk`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES ('1870484839812517890', 'openuser', 'ak-eAU25mrMxhtaZsyS', 'rjxMqB6YyUXpSHAz4DCIz8vZ5aozQQiV', NULL, '2024-12-21 23:01:52', NULL, NULL);
|
||||
@ -1 +0,0 @@
|
||||
INSERT INTO `open_api_permission` (`id`, `api_id`, `api_auth_id`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES ('1870491556923179010', '1870486348755324929', '1870484839812517890', NULL, '2024-12-21 23:28:34', NULL, NULL);
|
||||
@ -1,4 +0,0 @@
|
||||
INSERT INTO `open_api_record` (`id`, `api_id`, `call_auth_id`, `call_time`, `used_time`, `response_time`) VALUES ('1870491654130368513', '1870486348755324929', '1870484839812517890', '2024-12-21 23:28:57', 184, '2024-12-21 23:28:57');
|
||||
INSERT INTO `open_api_record` (`id`, `api_id`, `call_auth_id`, `call_time`, `used_time`, `response_time`) VALUES ('1870492694183542786', '1870486348755324929', '1870484839812517890', '2024-12-21 23:31:04', 120717, '2024-12-21 23:33:05');
|
||||
INSERT INTO `open_api_record` (`id`, `api_id`, `call_auth_id`, `call_time`, `used_time`, `response_time`) VALUES ('1870493301040680961', '1870486348755324929', '1870484839812517890', '2024-12-21 23:35:26', 3865, '2024-12-21 23:35:30');
|
||||
INSERT INTO `open_api_record` (`id`, `api_id`, `call_auth_id`, `call_time`, `used_time`, `response_time`) VALUES ('1870493334939045889', '1870486348755324929', '1870484839812517890', '2024-12-21 23:35:38', 82, '2024-12-21 23:35:38');
|
||||
Loading…
x
Reference in New Issue
Block a user