mirror of
https://github.com/eolinker/apinto
synced 2025-10-10 11:10:24 +08:00
修复了json schema 格式中 array下如果只有一个数据并且数据格式为对象时 解析失败bug
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user