(errorMessage, jsonPath, frontmatterContent string)
| 290 | } |
| 291 | |
| 292 | func 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 | |
| 315 | func additionalPropertiesSuggestion(schemaDoc any, errorMessage, jsonPath string) string { |
| 316 | lowerError := strings.ToLower(errorMessage) |
no test coverage detected