annotateSchemaWithAtomMeta applies AtomMeta annotations to a JSON schema
(schema map[string]any, meta *AtomMeta)
| 148 | |
| 149 | // annotateSchemaWithAtomMeta applies AtomMeta annotations to a JSON schema |
| 150 | func annotateSchemaWithAtomMeta(schema map[string]any, meta *AtomMeta) { |
| 151 | if meta == nil { |
| 152 | return |
| 153 | } |
| 154 | |
| 155 | if meta.Description != "" { |
| 156 | schema["description"] = meta.Description |
| 157 | } |
| 158 | |
| 159 | if meta.Units != "" { |
| 160 | schema["units"] = meta.Units |
| 161 | } |
| 162 | |
| 163 | // Add numeric constraints for number/integer types |
| 164 | if schema["type"] == "number" || schema["type"] == "integer" { |
| 165 | if meta.Min != nil { |
| 166 | schema["minimum"] = *meta.Min |
| 167 | } |
| 168 | if meta.Max != nil { |
| 169 | schema["maximum"] = *meta.Max |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | // Add enum values if specified (only for string types) |
| 174 | if len(meta.Enum) > 0 && schema["type"] == "string" { |
| 175 | enumValues := make([]any, len(meta.Enum)) |
| 176 | for i, v := range meta.Enum { |
| 177 | enumValues[i] = v |
| 178 | } |
| 179 | schema["enum"] = enumValues |
| 180 | } |
| 181 | |
| 182 | // Add pattern constraint for strings |
| 183 | if schema["type"] == "string" && meta.Pattern != "" { |
| 184 | schema["pattern"] = meta.Pattern |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | // generateShallowJSONSchema creates a schema that references definitions instead of recursing |
| 189 | func generateShallowJSONSchema(t reflect.Type, meta *AtomMeta) map[string]any { |
no outgoing calls
no test coverage detected