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

Function additionalPropertiesSuggestion

pkg/parser/schema_suggestions.go:315–336  ·  view source on GitHub ↗
(schemaDoc any, errorMessage, jsonPath string)

Source from the content-addressed store, hash-verified

313}
314
315func additionalPropertiesSuggestion(schemaDoc any, errorMessage, jsonPath string) string {
316 lowerError := strings.ToLower(errorMessage)
317 if !strings.Contains(lowerError, "additional propert") || !strings.Contains(lowerError, "not allowed") {
318 return ""
319 }
320
321 schemaSuggestionsLog.Print("Detected additional properties error")
322 invalidProps := extractAdditionalPropertyNames(errorMessage)
323 acceptedFields := extractAcceptedFieldsFromSchema(schemaDoc, jsonPath)
324 var suggestions []string
325 if len(acceptedFields) > 0 {
326 schemaSuggestionsLog.Printf("Found %d accepted fields for invalid properties %v", len(acceptedFields), invalidProps)
327 if s := generateFieldSuggestions(invalidProps, acceptedFields); s != "" {
328 suggestions = append(suggestions, s)
329 }
330 }
331 if s := generatePathLocationSuggestion(invalidProps, schemaDoc, jsonPath); s != "" {
332 schemaSuggestionsLog.Printf("Found path location suggestion: %s", s)
333 suggestions = append(suggestions, s)
334 }
335 return strings.Join(suggestions, ". ")
336}
337
338func rangeConstraintSuggestion(schemaDoc any, errorMessage, jsonPath string) string {
339 lowerMsg := strings.ToLower(errorMessage)

Callers 1

Calls 7

generateFieldSuggestionsFunction · 0.85
ToLowerMethod · 0.80
PrintMethod · 0.80
PrintfMethod · 0.45

Tested by

no test coverage detected