fix(接口测试): 修复导出接口为swagger格式-json请求体数据丢失问题
--bug=1025439 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001025439
This commit is contained in:
parent
9864e364f1
commit
81483dd438
|
@ -792,7 +792,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
||||||
JSONObject schema = new JSONObject();
|
JSONObject schema = new JSONObject();
|
||||||
schema.put(PropertyConstant.TYPE, PropertyConstant.OBJECT);
|
schema.put(PropertyConstant.TYPE, PropertyConstant.OBJECT);
|
||||||
JSONObject properties = buildSchema(requestBody);
|
JSONObject properties = buildSchema(requestBody);
|
||||||
schema.put(PropertyConstant.REQUIRED, properties);
|
schema.put(PropertyConstant.PROPERTIES, properties);
|
||||||
return schema;
|
return schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -806,7 +806,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
||||||
Object example = requestBody.get(0);
|
Object example = requestBody.get(0);
|
||||||
if (example instanceof JSONObject) {
|
if (example instanceof JSONObject) {
|
||||||
items.put(PropertyConstant.TYPE, PropertyConstant.OBJECT);
|
items.put(PropertyConstant.TYPE, PropertyConstant.OBJECT);
|
||||||
items.put(PropertyConstant.REQUIRED, buildSchema((JSONObject) example));
|
items.put(PropertyConstant.PROPERTIES, buildSchema((JSONObject) example));
|
||||||
} else if (example instanceof String) {
|
} else if (example instanceof String) {
|
||||||
items.put(PropertyConstant.TYPE, PropertyConstant.STRING);
|
items.put(PropertyConstant.TYPE, PropertyConstant.STRING);
|
||||||
} else if (example instanceof Integer) {
|
} else if (example instanceof Integer) {
|
||||||
|
@ -1227,10 +1227,13 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
||||||
bodyInfo = buildJsonSchema(jsonObject, required);
|
bodyInfo = buildJsonSchema(jsonObject, required);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try { // 若请求体是一个 object
|
String raw = body.optString("raw");
|
||||||
bodyInfo = buildRequestBodyJsonInfo(body.optJSONArray("raw"));
|
if (StringUtils.isNotBlank(raw)) {
|
||||||
} catch (Exception e) {
|
if (StringUtils.startsWith(raw, "[") && StringUtils.endsWith(raw, "]")) {
|
||||||
bodyInfo = buildRequestBodyJsonInfo(body.optJSONObject("raw"));
|
bodyInfo = buildRequestBodyJsonInfo(JSONUtil.parseArray(raw));
|
||||||
|
} else {
|
||||||
|
bodyInfo = buildRequestBodyJsonInfo(JSONUtil.parseObject(raw));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e1) { // 若请求体 json 不合法,则忽略错误,原样字符串导出/导入
|
} catch (Exception e1) { // 若请求体 json 不合法,则忽略错误,原样字符串导出/导入
|
||||||
|
|
Loading…
Reference in New Issue