修复了json schema 格式中 array下如果只有一个数据并且数据格式为对象时 解析失败bug

This commit is contained in:
zhangzeyi
2023-03-02 17:26:06 +08:00
parent e10b07ff4f
commit 9cb08b3ebc
2 changed files with 192 additions and 3 deletions

View File

@@ -173,8 +173,23 @@ func JsonSchemaMockJsUnmarshal(valueMap interface{}) interface{} {
randomNum = int(RandInt64(int64(minVal), int64(maxVal)))
}
if randomNum == 1 { //随机选取一个
resultMap[name] = templateList[rand.Intn(len(templateList))]
if randomNum == 1 {
if len(templateList) > 1 {
resultMap[name] = templateList[rand.Intn(len(templateList))]
continue
}
switch templateVal := templateList[0].(type) {
case map[string]interface{}:
tempMap := make(map[string]interface{})
for key, val := range templateVal {
split := strings.Split(key, "|")
tempMap[split[0]] = mockConstant(val)
}
resultMap[name] = tempMap
default:
resultMap[name] = templateVal
}
continue
}