generateSchemaBasedSuggestions generates helpful suggestions based on the schema and error type. frontmatterContent is the raw YAML frontmatter text, used to extract the user's typed value for enum suggestions.
(schemaJSON, errorMessage, jsonPath, frontmatterContent string)
| 36 | // generateSchemaBasedSuggestions generates helpful suggestions based on the schema and error type. |
| 37 | // frontmatterContent is the raw YAML frontmatter text, used to extract the user's typed value for enum suggestions. |
| 38 | func generateSchemaBasedSuggestions(schemaJSON, errorMessage, jsonPath, frontmatterContent string) string { |
| 39 | schemaSuggestionsLog.Printf("Generating schema suggestions: path=%s, schema_size=%d bytes", jsonPath, len(schemaJSON)) |
| 40 | schemaDoc, err := getParsedSchemaDoc(schemaJSON) |
| 41 | if err != nil { |
| 42 | schemaSuggestionsLog.Printf("Failed to parse schema JSON: %v", err) |
| 43 | return "" |
| 44 | } |
| 45 | |
| 46 | if suggestion, handled := enumSuggestion(errorMessage, jsonPath, frontmatterContent); handled { |
| 47 | return suggestion |
| 48 | } |
| 49 | |
| 50 | if suggestion := additionalPropertiesSuggestion(schemaDoc, errorMessage, jsonPath); suggestion != "" { |
| 51 | return suggestion |
| 52 | } |
| 53 | |
| 54 | if suggestion := rangeConstraintSuggestion(schemaDoc, errorMessage, jsonPath); suggestion != "" { |
| 55 | return suggestion |
| 56 | } |
| 57 | |
| 58 | if suggestion := typeMismatchSuggestion(schemaDoc, errorMessage, jsonPath); suggestion != "" { |
| 59 | return suggestion |
| 60 | } |
| 61 | |
| 62 | schemaSuggestionsLog.Print("No suggestions generated for error") |
| 63 | return "" |
| 64 | } |
| 65 | |
| 66 | // extractSchemaExamples navigates the schema to the given JSON path using |
| 67 | // navigateToSchemaPath and returns any "examples" array entries as formatted strings. |