MCPcopy Create free account
hub / github.com/astercloud/aster / validateObject

Method validateObject

pkg/memory/schema.go:168–191  ·  view source on GitHub ↗

validateObject 验证对象

(value any)

Source from the content-addressed store, hash-verified

166
167// validateObject 验证对象
168func (s *JSONSchema) validateObject(value any) error {
169 obj, ok := value.(map[string]any)
170 if !ok {
171 return fmt.Errorf("expected object, got %T", value)
172 }
173
174 // 验证必需字段
175 for _, reqField := range s.Required {
176 if _, exists := obj[reqField]; !exists {
177 return fmt.Errorf("required field '%s' is missing", reqField)
178 }
179 }
180
181 // 验证各个属性
182 for name, propSchema := range s.Properties {
183 if propVal, exists := obj[name]; exists {
184 if err := propSchema.validateValue(propVal); err != nil {
185 return fmt.Errorf("property '%s': %w", name, err)
186 }
187 }
188 }
189
190 return nil
191}
192
193// validateArray 验证数组
194func (s *JSONSchema) validateArray(value any) error {

Callers 1

validateValueMethod · 0.95

Calls 1

validateValueMethod · 0.80

Tested by

no test coverage detected