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

Function enumSuggestion

pkg/parser/schema_suggestions.go:292–313  ·  view source on GitHub ↗
(errorMessage, jsonPath, frontmatterContent string)

Source from the content-addressed store, hash-verified

290}
291
292func enumSuggestion(errorMessage, jsonPath, frontmatterContent string) (string, bool) {
293 if !strings.Contains(strings.ToLower(errorMessage), "value must be one of") {
294 return "", false
295 }
296
297 schemaSuggestionsLog.Print("Detected enum constraint violation")
298 enumValues := extractEnumValuesFromError(errorMessage)
299 actualPath := extractEnumConstraintPath(errorMessage, jsonPath)
300 userValue := extractYAMLValueAtPath(frontmatterContent, actualPath)
301 if userValue == "" || len(enumValues) == 0 {
302 return "", true
303 }
304
305 closest := sliceutil.Deduplicate(stringutil.FindClosestMatches(userValue, enumValues, maxClosestMatches))
306 if len(closest) == 1 {
307 return fmt.Sprintf("Did you mean '%s'?", closest[0]), true
308 }
309 if len(closest) > 1 {
310 return fmt.Sprintf("Did you mean: %s?", strings.Join(closest, ", ")), true
311 }
312 return "", true
313}
314
315func additionalPropertiesSuggestion(schemaDoc any, errorMessage, jsonPath string) string {
316 lowerError := strings.ToLower(errorMessage)

Callers 1

Calls 7

DeduplicateFunction · 0.92
FindClosestMatchesFunction · 0.92
extractYAMLValueAtPathFunction · 0.85
ToLowerMethod · 0.80
PrintMethod · 0.80

Tested by

no test coverage detected