fix(接口测试): 修复jsonSchema参数不符合预期的缺陷

--bug=1036894 --user=王孝刚 【接口测试】github#29213接口测试,请求体为json数组时,开启JSON-SCHEMA,发出去的请求体为空,关闭JSON-SCHEMA,json-object变为字符串 https://www.tapd.cn/55049933/s/1517736
This commit is contained in:
wxg0103 2024-05-21 16:03:05 +08:00 committed by Craftsman
parent 6a94b4d742
commit 4b1cdb413e
2 changed files with 8 additions and 5 deletions

View File

@ -45,7 +45,7 @@ public class JSONSchemaBuilder {
formatObject(map, allOfElementObj, rootObj);
}
}
} else if (object.has(PropertyConstant.PROPERTIES)) {
} else if (object.has(PropertyConstant.PROPERTIES) && !object.get(PropertyConstant.PROPERTIES).getAsJsonObject().isEmpty()) {
formatObject(map, object, rootObj);
} else if (object.has(PropertyConstant.TYPE)) {
if (object.get(PropertyConstant.TYPE).getAsString().equals(PropertyConstant.ARRAY)) {
@ -256,7 +256,7 @@ public class JSONSchemaBuilder {
}
private static void formatObject(Map<String, String> map, JsonObject jsonObject, JSONObject concept) {
JsonObject propertiesObj = jsonObject.has(PropertyConstant.PROPERTIES) ? jsonObject.get(PropertyConstant.PROPERTIES).getAsJsonObject(): new JsonObject();
JsonObject propertiesObj = jsonObject.has(PropertyConstant.PROPERTIES) ? jsonObject.get(PropertyConstant.PROPERTIES).getAsJsonObject() : new JsonObject();
for (Entry<String, JsonElement> entry : propertiesObj.entrySet()) {
String propertyKey = entry.getKey();
JsonObject propertyObj = propertiesObj.get(propertyKey).getAsJsonObject();
@ -285,7 +285,7 @@ public class JSONSchemaBuilder {
JSONArray jsonArray = (JSONArray) root.get(PropertyConstant.MS_OBJECT);
List<String> list = new LinkedList<>();
JSONSchemaParser.toJsonString(jsonArray, list);
return JSON.toJSONString(list);
return list.toString();
}
return JSON.toJSONString(JSON.toMap(root));
}

View File

@ -13,7 +13,10 @@ import org.json.JSONObject;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class JSONSchemaParser {
@ -236,7 +239,7 @@ public class JSONSchemaParser {
JSONArray jsonArray = (JSONArray) root.get(PropertyConstant.MS_OBJECT);
List<String> list = new LinkedList<>();
toJsonString(jsonArray, list);
json = JSON.toJSONString(list);
json = list.toString();
} else {
json = JSON.toJSONString(JSON.toMap(root));
}