MCPcopy Create free account
hub / github.com/github/gh-aw / navigateToSchemaPath

Function navigateToSchemaPath

pkg/parser/schema_suggestions.go:117–152  ·  view source on GitHub ↗

navigateToSchemaPath navigates to the appropriate schema section for a given JSON path

(schema map[string]any, jsonPath string)

Source from the content-addressed store, hash-verified

115
116// navigateToSchemaPath navigates to the appropriate schema section for a given JSON path
117func 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
155func resolveSchemaWithOneOf(schema map[string]any) map[string]any {

Callers 3

extractSchemaExamplesFunction · 0.85

Calls 4

parseJSONPathFunction · 0.85
resolveSchemaWithOneOfFunction · 0.85
PrintMethod · 0.80
PrintfMethod · 0.45

Tested by

no test coverage detected