resolveRefInSchema looks up a $ref value in the schema
(schema map[string]any, refPath string)
| 428 | |
| 429 | // resolveRefInSchema looks up a $ref value in the schema |
| 430 | func resolveRefInSchema(schema map[string]any, refPath string) string { |
| 431 | // Handle the # prefix - it indicates the root of the schema JSON |
| 432 | refPath = strings.TrimPrefix(refPath, "#") |
| 433 | |
| 434 | // Parse the JSON pointer path |
| 435 | pathParts := strings.Split(strings.TrimPrefix(refPath, "/"), "/") |
| 436 | |
| 437 | // Navigate through the schema to find the $ref value |
| 438 | var current any = schema |
| 439 | for _, part := range pathParts { |
| 440 | if part == "" { |
| 441 | continue |
| 442 | } |
| 443 | |
| 444 | if part == "$ref" { |
| 445 | // We've reached the $ref, return its value |
| 446 | if currentMap, ok := current.(map[string]any); ok { |
| 447 | if refValue, ok := currentMap["$ref"].(string); ok { |
| 448 | return refValue |
| 449 | } |
| 450 | } |
| 451 | return "" |
| 452 | } |
| 453 | |
| 454 | // Navigate to the next level |
| 455 | // Check if this is an array index |
| 456 | if index, err := strconv.Atoi(part); err == nil { |
| 457 | // This is an array index - check if current element is an array |
| 458 | if arr, ok := current.([]any); ok && index < len(arr) { |
| 459 | current = arr[index] |
| 460 | } else { |
| 461 | // Current element is not an array or index out of bounds |
| 462 | return "" |
| 463 | } |
| 464 | } else { |
| 465 | // This is a map key |
| 466 | if currentMap, ok := current.(map[string]any); ok { |
| 467 | current = currentMap[part] |
| 468 | } else { |
| 469 | // Current element is not a map |
| 470 | return "" |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | return "" |
| 476 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…