@@ -62,16 +62,15 @@ func validateJSONSchema(identifier string, schemaMap map[string]any, data any) e
62
62
for _ , validationErr := range validationError .DetailedOutput ().Errors {
63
63
pth := strings .TrimPrefix (validationErr .InstanceLocation , "/" )
64
64
65
- //nolint:errcheck // Why: Best effort way to get the error.
66
- b , _ := validationErr .Error .MarshalJSON ()
65
+ errStrs := recurseError (& validationErr , []string {})
67
66
68
- errStr := strings . TrimSuffix ( strings . TrimPrefix ( string ( b ), " \" " ), " \" " )
67
+ //nolint:errcheck // Why: Best effort way to get the error.
69
68
if pth == "" {
70
69
// Can't provide detailed field information. Wrapped error
71
70
// will provide the top-level location.
72
- errs = append (errs , fmt .Errorf ("%s" , errStr ))
71
+ errs = append (errs , fmt .Errorf ("%s" , strings . Join ( errStrs , ", " ) ))
73
72
} else {
74
- errs = append (errs , fmt .Errorf ("%s: %s" , pth , errStr ))
73
+ errs = append (errs , fmt .Errorf ("%s: %s" , pth , strings . Join ( errStrs , ", " ) ))
75
74
}
76
75
}
77
76
} else {
@@ -83,3 +82,20 @@ func validateJSONSchema(identifier string, schemaMap map[string]any, data any) e
83
82
84
83
return nil
85
84
}
85
+
86
+ // recurseError recursively traverses the output unit struct which has both singular and plural error fields,
87
+ // returning a slice of error strings that it's adding onto.
88
+ func recurseError (ou * jsonschema.OutputUnit , errStrs []string ) []string {
89
+ if ou .Error != nil {
90
+ //nolint:errcheck // Why: Best effort way to get the error.
91
+ b , _ := ou .Error .MarshalJSON ()
92
+
93
+ errStr := strings .TrimSuffix (strings .TrimPrefix (string (b ), "\" " ), "\" " )
94
+ errStrs = append (errStrs , errStr )
95
+ } else if len (ou .Errors ) > 0 {
96
+ for _ , ne := range ou .Errors {
97
+ recurseError (& ne , errStrs )
98
+ }
99
+ }
100
+ return errStrs
101
+ }
0 commit comments