diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/PostmanAbstractParserParser.java b/api-test/backend/src/main/java/io/metersphere/api/parse/PostmanAbstractParserParser.java index b6b8db6108..015406eb8b 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/PostmanAbstractParserParser.java +++ b/api-test/backend/src/main/java/io/metersphere/api/parse/PostmanAbstractParserParser.java @@ -68,6 +68,8 @@ public abstract class PostmanAbstractParserParser extends ApiImportAbstractPa parseBody(request.getBody(), requestDesc); request.setArguments(parseKeyValue(url == null ? new ArrayList<>() : url.getQuery())); request.setHeaders(parseKeyValue(requestDesc.getHeader())); + request.setCustomizeReq(true); + request.setReferenced("Created"); return request; } diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/mock/MockApiUtils.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/mock/MockApiUtils.java index e7bd36cc2c..a5dcb6841e 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/mock/MockApiUtils.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/mock/MockApiUtils.java @@ -727,10 +727,32 @@ public class MockApiUtils { for (String path : urlList) { if (StringUtils.equalsAny(path, url, "/" + url)) { return true; - } else { - if (StringUtils.isEmpty(path)) { - continue; + } else if (StringUtils.isEmpty(path)) { + return false; + } else if (StringUtils.startsWithAny(path.toLowerCase(), "https://", "http://")) { + if (path.contains("?")) { + path = path.substring(0, path.indexOf("?")); } + String[] pathArr = path.split("/"); + if (pathArr.length >= urlParams.length) { + boolean isFetch = true; + for (int urlIndex = 0; urlIndex < urlParams.length; urlIndex++) { + String urlItem = urlParams[urlIndex]; + String customUrlItem = pathArr[pathArr.length - urlParams.length + urlIndex]; + // 不为rest参数的要进行全匹配。 而且忽略大小写 + if (isRestUrlParam(customUrlItem) && isRestUrlParam(urlItem)) { + if (!StringUtils.equalsIgnoreCase(customUrlItem, urlItem)) { + isFetch = false; + break; + } + } + } + if (isFetch) { + return true; + } + } + } else { + if (path.startsWith("/")) { path = path.substring(1); } @@ -741,7 +763,7 @@ public class MockApiUtils { for (int i = 0; i < urlParams.length; i++) { String pathItem = pathArr[i]; String urlItem = urlParams[i]; - if (!(pathItem.startsWith("{") && pathItem.endsWith("}")) && !(urlItem.startsWith("{") && urlItem.endsWith("}"))) { + if (!(isRestUrlParam(pathItem)) && !(isRestUrlParam(urlItem))) { if (!StringUtils.equals(pathArr[i], urlParams[i])) { isFetch = false; break; @@ -763,6 +785,10 @@ public class MockApiUtils { return false; } + private static boolean isRestUrlParam(String urlParam) { + return !StringUtils.startsWith(urlParam, "{") || !StringUtils.endsWith(urlParam, "}") || StringUtils.equals(urlParam, "{}"); + } + /** * 匹配自定义URL是否匹配:截取前面的域名等信息 *