Skip to content

Commit 8bd5742

Browse files
authored
improve anyOf errors (#61)
Include all the sub-errors.
1 parent e5cd592 commit 8bd5742

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎jsonschema/validate.go‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,15 @@ func (st *state) validate(instance reflect.Value, schema *Schema, callerAnns *an
262262
}
263263
if schema.AnyOf != nil {
264264
// We must visit them all, to collect annotations.
265-
ok := false
265+
var errs []error
266266
for _, ss := range schema.AnyOf {
267-
if valid(ss, &anns) {
268-
ok = true
267+
if err := st.validate(instance, ss, &anns); err != nil {
268+
errs = append(errs, err)
269269
}
270270
}
271-
if !ok {
272-
return fmt.Errorf("anyOf: did not validate against any of %v", schema.AnyOf)
271+
if len(errs) == len(schema.AnyOf) {
272+
return fmt.Errorf("anyOf: did not validate against any of %v:\n%v",
273+
schema.AnyOf, errors.Join(errs...))
273274
}
274275
}
275276
if schema.OneOf != nil {

0 commit comments

Comments
 (0)