fix: 修复 schema 清理逻辑

This commit is contained in:
0xff26b9a8
2026-01-21 10:58:39 +08:00
committed by song
parent 71f8b9e473
commit 498c6cfae9

View File

@@ -146,17 +146,10 @@ func cleanJSONSchemaRecursive(value any) any {
for _, v := range schemaMap {
if _, isMap := v.(map[string]any); isMap {
cleanJSONSchemaRecursive(v)
} else if _, isArr := v.([]any); isArr {
// 数组内的对象也要递归
}
}
// 稍微补全一下数组递归
for k, v := range schemaMap {
if arr, ok := v.([]any); ok {
} else if arr, isArr := v.([]any); isArr {
for _, item := range arr {
cleanJSONSchemaRecursive(item)
}
schemaMap[k] = arr
}
}
}
@@ -455,18 +448,18 @@ func mergeAllOf(m map[string]any) {
}
if len(mergedReq) > 0 {
existReq, _ := m["required"].([]any)
var currentReqs []string
var validReqs []any
for _, r := range existReq {
if s, ok := r.(string); ok {
currentReqs = append(currentReqs, s)
validReqs = append(validReqs, s)
delete(mergedReq, s) // already exists
}
}
// append new
for r := range mergedReq {
existReq = append(existReq, r)
validReqs = append(validReqs, r)
}
m["required"] = existReq
m["required"] = validReqs
}
}