Refactor formatErrorContext to centralize schema guidance and remove duplicated addDetail logic#6797
Merged
Merged
Conversation
Closed
6 tasks
Copilot
AI
changed the title
[WIP] Refactor duplicate addDetail calls in formatErrorContext
Refactor May 31, 2026
formatErrorContext to centralize schema guidance and remove duplicated addDetail logic
Collaborator
|
@copilot resolve the merge conflicts in this pull request |
Contributor
Author
Resolved the merge conflicts and updated the branch in commit |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors JSON Schema validation error formatting to centralize keyword-to-guidance strings so both the keyword-location path and the message-fallback path use the same source of truth, reducing drift risk in user-facing diagnostics.
Changes:
- Introduces
detailForKeyword(keyword string) (string, []string)to own all guidance text for supported JSON Schema keywords (including shared"range"guidance). - Updates
formatErrorContextto route both its primary (keyword-location) and fallback (message-based) classification paths through the shared helper. - Adds focused tests for range inference via keyword location and for
detailForKeywordbehavior on known/unknown keywords.
Show a summary per file
| File | Description |
|---|---|
| internal/config/validation_schema.go | Centralizes validation guidance text and reuses it across both keyword-location and message-fallback error classification paths. |
| internal/config/validation_schema_error_format_test.go | Adds coverage for the new helper and for range inference via keyword-location (e.g., /minimum). |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
formatErrorContextduplicated the sameaddDetail()guidance across both keyword-based and message-fallback paths, creating drift risk when updating validation help text. This change centralizes keyword-to-guidance mapping so both paths use one source of truth while preserving existing fallback behavior.Centralize detail text in a single helper
detailForKeyword(keyword string) (string, []string)to own all guidance strings for:additionalProperties,type,enum,required,pattern,range,oneOfUnify primary and fallback classification paths
addFromKeywordinformatErrorContextto route throughdetailForKeyword.addDetail(...)blocks in:strings.Contains(...)checks (fallback path)minimum,maximum,exclusiveMinimum,exclusiveMaximum) now map through the shared"range"entry.Expand focused coverage around the new abstraction
TestFormatErrorContextcase for range inference from keyword location (.../minimum).TestDetailForKeywordto verify: