ensurePropertyTypes recursively walks a JSON Schema map and ensures every property has a "type" set, defaulting to "object" if missing. It descends into nested "properties" and array "items".
(schema map[string]any)
| 136 | // every property has a "type" set, defaulting to "object" if missing. |
| 137 | // It descends into nested "properties" and array "items". |
| 138 | func ensurePropertyTypes(schema map[string]any) { |
| 139 | props, ok := schema["properties"].(map[string]any) |
| 140 | if !ok { |
| 141 | return |
| 142 | } |
| 143 | |
| 144 | for _, v := range props { |
| 145 | prop, ok := v.(map[string]any) |
| 146 | if !ok { |
| 147 | continue |
| 148 | } |
| 149 | |
| 150 | if prop["type"] == nil { |
| 151 | prop["type"] = "object" |
| 152 | } |
| 153 | |
| 154 | // Recurse into nested object properties. |
| 155 | ensurePropertyTypes(prop) |
| 156 | |
| 157 | // Recurse into array items. |
| 158 | if items, ok := prop["items"].(map[string]any); ok { |
| 159 | ensurePropertyTypes(items) |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | func ConvertSchema(params, v any) error { |
| 165 | // First unmarshal to a map to check we have a type and non-nil properties |