Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions pkg/parser/schema_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package parser
import (
"fmt"
"regexp"
"sort"
"strings"
)

Expand Down Expand Up @@ -211,9 +212,7 @@ func rewriteAdditionalPropertiesError(message string) string {
match := re.FindStringSubmatch(message)

if len(match) >= 2 {
properties := match[1]
// Clean up the property list and make it more readable
properties = strings.ReplaceAll(properties, "'", "")
properties := normalizeAdditionalPropertyList(match[1])

if strings.Contains(properties, ",") {
return "Unknown properties: " + properties
Expand All @@ -225,3 +224,17 @@ func rewriteAdditionalPropertiesError(message string) string {

return message
}

func normalizeAdditionalPropertyList(raw string) string {
raw = strings.ReplaceAll(raw, "'", "")
parts := strings.Split(raw, ",")
cleaned := make([]string, 0, len(parts))
for _, part := range parts {
trimmed := strings.TrimSpace(part)
if trimmed != "" {
cleaned = append(cleaned, trimmed)
}
}
sort.Strings(cleaned)
return strings.Join(cleaned, ", ")
}
31 changes: 31 additions & 0 deletions pkg/parser/schema_errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,34 @@ func TestTranslateSchemaConstraintMessage(t *testing.T) {
})
}
}

func TestRewriteAdditionalPropertiesErrorOrdering(t *testing.T) {
tests := []struct {
name string
in string
want string
}{
{
name: "sorts multiple unknown properties",
in: "at '/safe-outputs': additional properties 'zeta', 'alpha', 'beta' not allowed",
want: "Unknown properties: alpha, beta, zeta",
},
{
name: "sorts and trims unquoted list",
in: "additional properties zeta, alpha, beta not allowed",
want: "Unknown properties: alpha, beta, zeta",
},
{
name: "single unknown property remains singular",
in: "additional property 'timeout_minutes' not allowed",
want: "Unknown property: timeout_minutes",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := rewriteAdditionalPropertiesError(tt.in)
assert.Equal(t, tt.want, got)
})
}
}
Loading