fix(接口定义): 修复jsonschema选择枚举运行没有生效的缺陷 (#17612)

--bug=1016488 --user=王孝刚 【接口测试】github #17514,场景中使用枚举,执行接口,请求内容未使用枚举值
https://www.tapd.cn/55049933/s/1236649

Co-authored-by: wxg0103 <727495428@qq.com>
This commit is contained in:
MeterSphere Bot 2022-09-01 13:59:09 +08:00 committed by GitHub
parent cc1d7ca5ab
commit 9312246003
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -2,7 +2,9 @@ package io.metersphere.commons.json;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.*;
import io.metersphere.commons.utils.EnumPropertyUtil;
import io.metersphere.jmeter.utils.ScriptEngineUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.NumberUtils;
@ -248,6 +250,12 @@ public class JSONSchemaRunTest {
if (isMock(object)) {
String value = ScriptEngineUtils.buildFunctionCallString(object.get(BasicConstant.MOCK).getAsJsonObject().get(BasicConstant.MOCK).getAsString());
return value;
} else if (object.has(BasicConstant.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) {
return object.get(BasicConstant.MOCK).getAsJsonObject().get(BasicConstant.MOCK);