fix(接口测试): 修复导入swagger文件报错的缺陷
--bug=1025986 --user=王孝刚 【接口测试】github#24191,接口定义导入swagger文件时报解析数据出错,实际检查文件没有格式及内容错误 https://www.tapd.cn/55049933/s/1368984
This commit is contained in:
parent
4e05a8937c
commit
b1045a29a1
|
@ -428,21 +428,38 @@ 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());
|
||||
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);
|
||||
if (StringUtils.isBlank(parameterStr)) {
|
||||
return;
|
||||
}
|
||||
if (bodyParameter.getSchema() instanceof ArrayModel) {
|
||||
JSONArray objects = JSONUtil.parseArray(parameterStr);
|
||||
if (objects.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
objects.forEach(item -> {
|
||||
setBodyKvs(body, (JSONObject) item);
|
||||
});
|
||||
|
||||
} else {
|
||||
JSONObject jsonObject = JSONUtil.parseObject(parameterStr);
|
||||
setBodyKvs(body, jsonObject);
|
||||
}
|
||||
|
||||
} else {
|
||||
body.setRaw(parseSchema(bodyParameter.getSchema()));
|
||||
}
|
||||
}
|
||||
|
||||
private static void setBodyKvs(Body body, JSONObject jsonObject) {
|
||||
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);
|
||||
}
|
||||
|
||||
private JsonSchemaItem parseSchema2JsonSchema(Model schema) {
|
||||
if (schema == null) return null;
|
||||
JsonSchemaItem item = new JsonSchemaItem();
|
||||
|
|
Loading…
Reference in New Issue