提交 0b7e98fb authored 作者: mry's avatar mry

fix(web): 修复了,url查询无效的问题

上级 cc7966e0
...@@ -76,8 +76,7 @@ public class SwaggerController { ...@@ -76,8 +76,7 @@ public class SwaggerController {
* @return 模糊查询的结果 * @return 模糊查询的结果
*/ */
public List<InterfaceInformation> search(String name, List<InterfaceInformation> list) { public List<InterfaceInformation> search(String name, List<InterfaceInformation> list) {
@SuppressWarnings(value = "all") @SuppressWarnings(value = "all") List<InterfaceInformation> results = new ArrayList();
List<InterfaceInformation> results = new ArrayList();
Pattern pattern = Pattern.compile(name, Pattern.CASE_INSENSITIVE); Pattern pattern = Pattern.compile(name, Pattern.CASE_INSENSITIVE);
for (InterfaceInformation o : list) { for (InterfaceInformation o : list) {
Matcher matcher = pattern.matcher(o.getTags()); Matcher matcher = pattern.matcher(o.getTags());
...@@ -103,8 +102,7 @@ public class SwaggerController { ...@@ -103,8 +102,7 @@ public class SwaggerController {
Object basePath = swaggerJson.get("basePath"); Object basePath = swaggerJson.get("basePath");
Object paths = swaggerJson.get("paths"); Object paths = swaggerJson.get("paths");
//将paths转成map集合 //将paths转成map集合
@SuppressWarnings(value = "unchecked") @SuppressWarnings(value = "unchecked") Map<String, String> pathsMaps = (Map<String, String>) paths;
Map<String, String> pathsMaps = (Map<String, String>) paths;
//获取key //获取key
Set<String> methodUrls = pathsMaps.keySet(); Set<String> methodUrls = pathsMaps.keySet();
List<InterfaceInformation> list = new ArrayList<>(); List<InterfaceInformation> list = new ArrayList<>();
...@@ -115,24 +113,20 @@ public class SwaggerController { ...@@ -115,24 +113,20 @@ public class SwaggerController {
//通过JSON获取到methodUrl,用来获取methodUrl内部的信息 //通过JSON获取到methodUrl,用来获取methodUrl内部的信息
Object objMethodUrls = objPaths.get(methodUrl); Object objMethodUrls = objPaths.get(methodUrl);
JSONObject objUrlsJson = (JSONObject) objMethodUrls; JSONObject objUrlsJson = (JSONObject) objMethodUrls;
@SuppressWarnings(value = "unchecked") @SuppressWarnings(value = "unchecked") Map<String, String> objMethodUrlsMaps = (Map<String, String>) objMethodUrls;
Map<String, String> objMethodUrlsMaps = (Map<String, String>) objMethodUrls;
Set<String> requests = objMethodUrlsMaps.keySet(); Set<String> requests = objMethodUrlsMaps.keySet();
for (String request : requests) { for (String request : requests) {
//拿到请求内部的信息 //拿到请求内部的信息
Object objRequest = objUrlsJson.get(request); Object objRequest = objUrlsJson.get(request);
@SuppressWarnings(value = "unchecked") @SuppressWarnings(value = "unchecked") Map<String, String> objRequestMaps = (Map<String, String>) objRequest;
Map<String, String> objRequestMaps = (Map<String, String>) objRequest;
Object parameters = objRequestMaps.get("parameters"); Object parameters = objRequestMaps.get("parameters");
Object tags = objRequestMaps.get("tags"); Object tags = objRequestMaps.get("tags");
Object summary = objRequestMaps.get("summary"); Object summary = objRequestMaps.get("summary");
List<Parameter> parameterAllList = new ArrayList<>(); List<Parameter> parameterAllList = new ArrayList<>();
InterfaceInformation interfaceInformation = new InterfaceInformation(); InterfaceInformation interfaceInformation = new InterfaceInformation();
@SuppressWarnings(value = "all") @SuppressWarnings(value = "all") List<String> parameterLists = parameters == null ? new ArrayList<>() : (List<String>) parameters;
List<String> parameterLists = parameters == null ? new ArrayList<>() : (List<String>) parameters;
for (Object parameterList : parameterLists) { for (Object parameterList : parameterLists) {
@SuppressWarnings(value = "unchecked") @SuppressWarnings(value = "unchecked") Map<String, String> parameterMaps = (Map<String, String>) parameterList;
Map<String, String> parameterMaps = (Map<String, String>) parameterList;
String methodIn = parameterMaps.get("in"); String methodIn = parameterMaps.get("in");
String methodName = parameterMaps.get("name"); String methodName = parameterMaps.get("name");
String methodType = parameterMaps.get("type"); String methodType = parameterMaps.get("type");
...@@ -173,35 +167,28 @@ public class SwaggerController { ...@@ -173,35 +167,28 @@ public class SwaggerController {
@GetMapping @GetMapping
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ApiOperation(value = "快速添加接口") @ApiOperation(value = "快速添加接口")
public CommonPage<List<InterfaceInformation>> parameter( public CommonPage<List<InterfaceInformation>> parameter(Long projectId, Long id, @RequestParam(defaultValue = "10") int pageSize, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(required = false, defaultValue = "") String name, @RequestParam(required = false, defaultValue = "") String swaggerUrl) {
Long projectId,
Long id,
@RequestParam(defaultValue = "10") int pageSize,
@RequestParam(defaultValue = "1") int pageNum,
@RequestParam(required = false,defaultValue = "")String name,
@RequestParam(required = false,defaultValue = "")String swaggerUrl) {
//将所有的默认选项置为false //将所有的默认选项置为false
environmentService.setIsDefaultByWrapper(false, environmentService.setIsDefaultByWrapper(false, Wrappers.lambdaQuery(Environment.class).eq(Environment::getProjectId, projectId));
Wrappers.lambdaQuery(Environment.class).eq(Environment::getProjectId, projectId));
//将选中的环境置为true,后续默认选择这个环境 //将选中的环境置为true,后续默认选择这个环境
environmentService.setIsDefaultByWrapper(true, environmentService.setIsDefaultByWrapper(true, Wrappers.lambdaQuery(Environment.class).eq(Environment::getId, id));
Wrappers.lambdaQuery(Environment.class).eq(Environment::getId, id));
Environment environment = environmentService.getById(id); Environment environment = environmentService.getById(id);
String url = String.format("%s/v2/api-docs", environment.getIp()); String url = String.format("%s/v2/api-docs", environment.getIp());
//获得json字符串 //获得json字符串
String json = loadJson(url); String json = loadJson(url);
List<InterfaceInformation> list = getList(json); List<InterfaceInformation> list = getList(json);
List<InterfaceInformation> swaggerUrlSearch; List<InterfaceInformation> swaggerUrlSearch;
if (swaggerUrl != null) { List<InterfaceInformation> swaggerNameSearch;
if ("".equals(swaggerUrl) && "".equals(name)) {
swaggerNameSearch = list;
} else if (!"".equals(swaggerUrl) && "".equals(name)) {
swaggerUrlSearch = search(swaggerUrl, list); swaggerUrlSearch = search(swaggerUrl, list);
swaggerNameSearch = swaggerUrlSearch;
} else if ("".equals(swaggerUrl) && !"".equals(name)) {
swaggerNameSearch = search(name, list);
} else { } else {
swaggerUrlSearch = list; swaggerUrlSearch = search(swaggerUrl, list);
}
List<InterfaceInformation> swaggerNameSearch;
if (name != null) {
swaggerNameSearch = search(name, swaggerUrlSearch); swaggerNameSearch = search(name, swaggerUrlSearch);
} else {
swaggerNameSearch = list;
} }
int total = swaggerNameSearch.size(); int total = swaggerNameSearch.size();
List<InterfaceInformation> subList = swaggerNameSearch.subList(pageSize * (pageNum - 1), (Math.min((pageNum * pageSize), total))); List<InterfaceInformation> subList = swaggerNameSearch.subList(pageSize * (pageNum - 1), (Math.min((pageNum * pageSize), total)));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论