validateArray 验证数组
(value any)
| 192 | |
| 193 | // validateArray 验证数组 |
| 194 | func (s *JSONSchema) validateArray(value any) error { |
| 195 | arr, ok := value.([]any) |
| 196 | if !ok { |
| 197 | return fmt.Errorf("expected array, got %T", value) |
| 198 | } |
| 199 | |
| 200 | // 验证数组元素 |
| 201 | if s.Items != nil { |
| 202 | for i, item := range arr { |
| 203 | if err := s.Items.validateValue(item); err != nil { |
| 204 | return fmt.Errorf("array item [%d]: %w", i, err) |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | return nil |
| 210 | } |
| 211 | |
| 212 | // NewJSONSchemaFromMap 从 map 创建 JSONSchema(方便从配置文件加载) |
| 213 | func NewJSONSchemaFromMap(m map[string]any) (*JSONSchema, error) { |
no test coverage detected