rewriteAdditionalPropertiesError rewrites "additional properties not allowed" errors to be more user-friendly
(message string)
| 445 | |
| 446 | // rewriteAdditionalPropertiesError rewrites "additional properties not allowed" errors to be more user-friendly |
| 447 | func rewriteAdditionalPropertiesError(message string) string { |
| 448 | // Check if this is an "additional properties not allowed" error |
| 449 | if strings.Contains(strings.ToLower(message), "additional propert") && strings.Contains(strings.ToLower(message), "not allowed") { |
| 450 | // Extract property names from the message using regex |
| 451 | match := additionalPropertiesPattern.FindStringSubmatch(message) |
| 452 | |
| 453 | if len(match) >= 2 { |
| 454 | properties := normalizeAdditionalPropertyList(match[1]) |
| 455 | schemaErrorsLog.Printf("Rewriting additional properties error: %s", properties) |
| 456 | |
| 457 | if strings.Contains(properties, ",") { |
| 458 | return "Unknown properties: " + properties |
| 459 | } else { |
| 460 | return "Unknown property: " + properties |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | return message |
| 466 | } |
| 467 | |
| 468 | // normalizeAdditionalPropertyList strips quotes, trims whitespace, and sorts the |
| 469 | // comma-separated property names so that diagnostics are deterministic regardless |