generateSchemaFromAtoms generates a JSON schema from a map of atoms
(atoms map[string]genAtom, title, description string)
| 248 | |
| 249 | // generateSchemaFromAtoms generates a JSON schema from a map of atoms |
| 250 | func 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 |
| 295 | func GenerateConfigSchema(root *RootElem) map[string]any { |
no test coverage detected