fix(接口测试): 修复swagger文件导入失败的缺陷

--bug=1025299 --user=王孝刚 【接口测试】github#23524,swagger文件导入不成功
https://www.tapd.cn/55049933/s/1361285
This commit is contained in:
wxg0103 2023-04-11 14:06:18 +08:00 committed by xiaomeinvG
parent f6ec5453f4
commit b31bfe8aac
2 changed files with 10 additions and 8 deletions

View File

@ -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<String> strings = jsonObject.keySet();
List<KeyValue> 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<String> strings = jsonObject.keySet();
List<KeyValue> 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()));
}

View File

@ -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) {