appendKnownFieldValidValuesHint appends a "Valid values: …" hint, "Did you mean?" suggestions, and a documentation link to message when the jsonPath matches a well-known field and the message is an unknown-property error. It returns the message unchanged for unknown paths or non-additional-propertie
(message string, jsonPath string)
| 351 | // It returns the message unchanged for unknown paths or non-additional-properties messages. |
| 352 | // The second return value is true if a hint was actually appended to the message. |
| 353 | func appendKnownFieldValidValuesHint(message string, jsonPath string) (string, bool) { |
| 354 | // Use truncated prefix "unknown propert" to match both singular ("Unknown property") |
| 355 | // and plural ("Unknown properties") forms produced by rewriteAdditionalPropertiesError. |
| 356 | if !strings.Contains(strings.ToLower(message), "unknown propert") { |
| 357 | return message, false |
| 358 | } |
| 359 | schemaErrorsLog.Printf("Appending known field hint for path: %s", jsonPath) |
| 360 | |
| 361 | hint, scopes, docsURL, hintOK := knownFieldHintForPath(jsonPath) |
| 362 | if !hintOK { |
| 363 | return message, false |
| 364 | } |
| 365 | |
| 366 | result := message + " (" + hint + ")" |
| 367 | result = appendKnownFieldSuggestions(result, message, scopes) |
| 368 | result = appendKnownFieldDocsURL(result, docsURL) |
| 369 | return result, true |
| 370 | } |
| 371 | |
| 372 | func knownFieldHintForPath(jsonPath string) (string, []string, string, bool) { |
| 373 | if hint, ok := knownFieldValidValues[jsonPath]; ok { |