collectStructDefs walks the type tree and adds struct definitions to defs map
(t reflect.Type, defs map[reflect.Type]any)
| 105 | |
| 106 | // collectStructDefs walks the type tree and adds struct definitions to defs map |
| 107 | func collectStructDefs(t reflect.Type, defs map[reflect.Type]any) { |
| 108 | switch t.Kind() { |
| 109 | case reflect.Slice, reflect.Array: |
| 110 | if t.Elem() != nil { |
| 111 | collectStructDefs(t.Elem(), defs) |
| 112 | } |
| 113 | case reflect.Map: |
| 114 | if t.Elem() != nil { |
| 115 | collectStructDefs(t.Elem(), defs) |
| 116 | } |
| 117 | case reflect.Struct: |
| 118 | // Skip time.Time since we handle it specially |
| 119 | if t == reflect.TypeOf(time.Time{}) { |
| 120 | return |
| 121 | } |
| 122 | |
| 123 | // Skip if we already have this struct definition |
| 124 | if _, exists := defs[t]; exists { |
| 125 | return |
| 126 | } |
| 127 | |
| 128 | // Create the struct definition |
| 129 | structDef := createStructDefinition(t) |
| 130 | |
| 131 | // Add the definition before recursing into field types |
| 132 | defs[t] = structDef |
| 133 | |
| 134 | // Now recurse into field types to collect their struct definitions |
| 135 | for i := 0; i < t.NumField(); i++ { |
| 136 | field := t.Field(i) |
| 137 | if field.IsExported() { |
| 138 | _, shouldInclude := util.ParseJSONTag(field) |
| 139 | if shouldInclude { |
| 140 | collectStructDefs(field.Type, defs) |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | case reflect.Ptr: |
| 145 | collectStructDefs(t.Elem(), defs) |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | // annotateSchemaWithAtomMeta applies AtomMeta annotations to a JSON schema |
| 150 | func annotateSchemaWithAtomMeta(schema map[string]any, meta *AtomMeta) { |
no test coverage detected