diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/api/Swagger2Parser.java b/api-test/backend/src/main/java/io/metersphere/api/parse/api/Swagger2Parser.java index f5732f7a1f..f2fd092e3f 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/api/Swagger2Parser.java +++ b/api-test/backend/src/main/java/io/metersphere/api/parse/api/Swagger2Parser.java @@ -428,14 +428,16 @@ public class Swagger2Parser extends SwaggerAbstractParser { body.setFormat("JSON-SCHEMA"); } else if (body.getType().equals(Body.WWW_FROM) || body.getType().equals(Body.FORM_DATA)) { String parameterStr = parseSchema(bodyParameter.getSchema()); - JSONObject jsonObject = JSONUtil.parseObject(parameterStr); - Set strings = jsonObject.keySet(); - List kvs = new ArrayList<>(); - for (String key : strings) { - KeyValue keyValue = new KeyValue(key, jsonObject.get(key).toString()); - kvs.add(keyValue); + if (StringUtils.isNotBlank(parameterStr)) { + JSONObject jsonObject = JSONUtil.parseObject(parameterStr); + Set strings = jsonObject.keySet(); + List kvs = new ArrayList<>(); + for (String key : strings) { + KeyValue keyValue = new KeyValue(key, jsonObject.get(key).toString()); + kvs.add(keyValue); + } + body.setKvs(kvs); } - body.setKvs(kvs); } else { body.setRaw(parseSchema(bodyParameter.getSchema())); } diff --git a/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java b/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java index d536fa06cc..3592cae377 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java @@ -828,7 +828,7 @@ public class MockConfigService { String urlPrefix = "/mock/" + projectId + "/"; String requestUri = request.getRequestURI(); String[] urlParamArr = requestUri.split(urlPrefix); - return urlParamArr[urlParamArr.length - 1]; + return urlParamArr.length == 0 ? "" : urlParamArr[urlParamArr.length - 1]; } public MockConfigResponse findByApiId(String id) {