(schemaDoc any, errorMessage, jsonPath string)
| 313 | } |
| 314 | |
| 315 | func 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 | |
| 338 | func rangeConstraintSuggestion(schemaDoc any, errorMessage, jsonPath string) string { |
| 339 | lowerMsg := strings.ToLower(errorMessage) |
no test coverage detected