navigateToSchemaPath navigates to the appropriate schema section for a given JSON path
(schema map[string]any, jsonPath string)
| 115 | |
| 116 | // navigateToSchemaPath navigates to the appropriate schema section for a given JSON path |
| 117 | func navigateToSchemaPath(schema map[string]any, jsonPath string) map[string]any { |
| 118 | if jsonPath == "" { |
| 119 | schemaSuggestionsLog.Print("Navigating to root schema path") |
| 120 | return schema // Root level |
| 121 | } |
| 122 | |
| 123 | // Parse the JSON path and navigate through the schema |
| 124 | schemaSuggestionsLog.Printf("Navigating schema path: %s", jsonPath) |
| 125 | pathSegments := parseJSONPath(jsonPath) |
| 126 | current := schema |
| 127 | |
| 128 | for _, segment := range pathSegments { |
| 129 | switch segment.Type { |
| 130 | case "key": |
| 131 | // Navigate to properties -> key |
| 132 | if properties, ok := current["properties"].(map[string]any); ok { |
| 133 | if keySchema, ok := properties[segment.Value].(map[string]any); ok { |
| 134 | current = resolveSchemaWithOneOf(keySchema) |
| 135 | } else { |
| 136 | return nil // Path not found in schema |
| 137 | } |
| 138 | } else { |
| 139 | return nil // No properties in current schema |
| 140 | } |
| 141 | case "index": |
| 142 | // For array indices, navigate to items schema |
| 143 | if items, ok := current["items"].(map[string]any); ok { |
| 144 | current = items |
| 145 | } else { |
| 146 | return nil // No items schema for array |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | return current |
| 152 | } |
| 153 | |
| 154 | // resolveSchemaWithOneOf resolves a schema that may contain oneOf, choosing the object variant for suggestions |
| 155 | func resolveSchemaWithOneOf(schema map[string]any) map[string]any { |
no test coverage detected