MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / generateSchemaFromAtoms

Function generateSchemaFromAtoms

tsunami/engine/schema.go:250–292  ·  view source on GitHub ↗

generateSchemaFromAtoms generates a JSON schema from a map of atoms

(atoms map[string]genAtom, title, description string)

Source from the content-addressed store, hash-verified

248
249// generateSchemaFromAtoms generates a JSON schema from a map of atoms
250func generateSchemaFromAtoms(atoms map[string]genAtom, title, description string) map[string]any {
251 // Collect all struct definitions
252 defs := make(map[reflect.Type]any)
253 for _, atom := range atoms {
254 atomType := atom.GetAtomType()
255 if atomType != nil {
256 collectStructDefs(atomType, defs)
257 }
258 }
259
260 // Generate properties for each atom
261 properties := make(map[string]any)
262 for atomName, atom := range atoms {
263 atomType := atom.GetAtomType()
264 if atomType != nil {
265 atomMeta := getAtomMeta(atom)
266 properties[atomName] = generateShallowJSONSchema(atomType, atomMeta)
267 }
268 }
269
270 // Build the final schema
271 // schema line unnecessary for AI (and burns tokens)
272 // also dropping title since it is mostly redundant
273 schema := map[string]any{
274 // "$schema": "https://json-schema.org/draft/2020-12/schema",
275 "type": "object",
276 // "title": title,
277 "description": description,
278 "properties": properties,
279 "additionalProperties": false,
280 }
281
282 // Add definitions if any
283 if len(defs) > 0 {
284 definitions := make(map[string]any)
285 for t, def := range defs {
286 definitions[t.Name()] = def
287 }
288 schema["$defs"] = definitions
289 }
290
291 return schema
292}
293
294// GenerateConfigSchema generates a JSON schema for all config atoms
295func GenerateConfigSchema(root *RootElem) map[string]any {

Callers 2

GenerateConfigSchemaFunction · 0.85
GenerateDataSchemaFunction · 0.85

Calls 5

collectStructDefsFunction · 0.85
getAtomMetaFunction · 0.85
GetAtomTypeMethod · 0.65
NameMethod · 0.45

Tested by

no test coverage detected