generateExampleJSONForPath generates an example JSON object for a specific schema path
(schemaDoc any, jsonPath string)
| 237 | |
| 238 | // generateExampleJSONForPath generates an example JSON object for a specific schema path |
| 239 | func generateExampleJSONForPath(schemaDoc any, jsonPath string) string { |
| 240 | schemaMap, ok := schemaDoc.(map[string]any) |
| 241 | if !ok { |
| 242 | return "" |
| 243 | } |
| 244 | |
| 245 | // Navigate to the target schema |
| 246 | targetSchema := navigateToSchemaPath(schemaMap, jsonPath) |
| 247 | if targetSchema == nil { |
| 248 | return "" |
| 249 | } |
| 250 | |
| 251 | // Generate example based on schema type |
| 252 | example := generateExampleFromSchema(targetSchema) |
| 253 | if example == nil { |
| 254 | return "" |
| 255 | } |
| 256 | |
| 257 | // Convert to JSON string |
| 258 | exampleJSON, err := json.Marshal(example) |
| 259 | if err != nil { |
| 260 | return "" |
| 261 | } |
| 262 | |
| 263 | return string(exampleJSON) |
| 264 | } |
| 265 | |
| 266 | // generateExampleFromSchema generates an example value based on a JSON schema |
| 267 | func generateExampleFromSchema(schema map[string]any) any { |