fix(接口测试): 修复接口定义执行时string取枚举值的缺陷
--bug=1020660 --user=王孝刚 【接口测试】json-schema请求体,string类型的参数值为空时会取枚举值 https://www.tapd.cn/55049933/s/1313197
This commit is contained in:
parent
7a9909c0c9
commit
b7a2e1fce0
|
@ -3,10 +3,8 @@ package io.metersphere.api.exec.generator;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import io.metersphere.commons.constants.PropertyConstant;
|
import io.metersphere.commons.constants.PropertyConstant;
|
||||||
import io.metersphere.commons.utils.EnumPropertyUtil;
|
|
||||||
import io.metersphere.commons.utils.JSONUtil;
|
import io.metersphere.commons.utils.JSONUtil;
|
||||||
import io.metersphere.jmeter.utils.ScriptEngineUtils;
|
import io.metersphere.jmeter.utils.ScriptEngineUtils;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
@ -14,7 +12,6 @@ import org.json.JSONObject;
|
||||||
import org.springframework.util.NumberUtils;
|
import org.springframework.util.NumberUtils;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
@ -252,12 +249,6 @@ public class JSONSchemaRunTest {
|
||||||
if (isMock(object)) {
|
if (isMock(object)) {
|
||||||
String value = ScriptEngineUtils.buildFunctionCallString(object.get(PropertyConstant.MOCK).getAsJsonObject().get(PropertyConstant.MOCK).getAsString());
|
String value = ScriptEngineUtils.buildFunctionCallString(object.get(PropertyConstant.MOCK).getAsJsonObject().get(PropertyConstant.MOCK).getAsString());
|
||||||
return value;
|
return value;
|
||||||
} else if (object.has(PropertyConstant.ENUM)) {
|
|
||||||
List<Object> list = EnumPropertyUtil.analyzeEnumProperty(object);
|
|
||||||
if (CollectionUtils.isNotEmpty(list)) {
|
|
||||||
int index = (int) (Math.random() * list.size());
|
|
||||||
return list.get(index);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return object.get(PropertyConstant.MOCK).getAsJsonObject().get(PropertyConstant.MOCK);
|
return object.get(PropertyConstant.MOCK).getAsJsonObject().get(PropertyConstant.MOCK);
|
||||||
|
|
Loading…
Reference in New Issue