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

Function NewJSONSchemaFromMap

pkg/memory/schema.go:213–230  ·  view source on GitHub ↗

NewJSONSchemaFromMap 从 map 创建 JSONSchema(方便从配置文件加载)

(m map[string]any)

Source from the content-addressed store, hash-verified

211
212// NewJSONSchemaFromMap 从 map 创建 JSONSchema(方便从配置文件加载)
213func NewJSONSchemaFromMap(m map[string]any) (*JSONSchema, error) {
214 // 序列化再反序列化,简单实现类型转换
215 jsonData, err := json.Marshal(m)
216 if err != nil {
217 return nil, fmt.Errorf("marshal schema map: %w", err)
218 }
219
220 var schema JSONSchema
221 if err := json.Unmarshal(jsonData, &schema); err != nil {
222 return nil, fmt.Errorf("unmarshal schema: %w", err)
223 }
224
225 if err := schema.Validate(); err != nil {
226 return nil, err
227 }
228
229 return &schema, nil
230}
231
232// ToMap 将 JSONSchema 转换为 map(方便序列化)
233func (s *JSONSchema) ToMap() map[string]any {

Callers

nothing calls this directly

Calls 1

ValidateMethod · 0.95

Tested by

no test coverage detected