@@ -235,4 +235,42 @@ void neverSchemaRejectsNull() {
235235 .extracting (t -> ((ValidationException ) t ).error ().keyword ())
236236 .isEqualTo ("false" );
237237 }
238+
239+ @ Test
240+ void oneOfZeroMatchesCapturesEachBranchError () {
241+ // "hello" (len 5): branch[0] minLength 100 fails, branch[1] maxLength 2 fails.
242+ var schema = new OneOfSchema (List .of (stringSchema (100 , null ), stringSchema (null , 2 )), Map .of ());
243+ assertThatThrownBy (() -> v .validate ("hello" , schema , "/v" ))
244+ .isInstanceOf (ValidationException .class )
245+ .satisfies (
246+ t -> {
247+ var err = ((ValidationException ) t ).error ();
248+ assertThat (err .branches ())
249+ .extracting (ValidationError ::keyword )
250+ .containsExactly ("minLength" , "maxLength" );
251+ });
252+ }
253+
254+ @ Test
255+ void oneOfTwoMatchesHasNoBranchErrors () {
256+ // Both branches accept "hello" — ambiguity, not a field error.
257+ var schema = new OneOfSchema (List .of (stringSchema (null , 10 ), stringSchema (1 , null )), Map .of ());
258+ assertThatThrownBy (() -> v .validate ("hello" , schema , "/v" ))
259+ .isInstanceOf (ValidationException .class )
260+ .satisfies (t -> assertThat (((ValidationException ) t ).error ().branches ()).isEmpty ());
261+ }
262+
263+ @ Test
264+ void anyOfNoMatchCapturesEachBranchError () {
265+ var schema = new AnyOfSchema (List .of (stringSchema (100 , null ), stringSchema (null , 2 )), Map .of ());
266+ assertThatThrownBy (() -> v .validate ("hello" , schema , "/v" ))
267+ .isInstanceOf (ValidationException .class )
268+ .satisfies (
269+ t -> {
270+ var err = ((ValidationException ) t ).error ();
271+ assertThat (err .branches ())
272+ .extracting (ValidationError ::keyword )
273+ .containsExactly ("minLength" , "maxLength" );
274+ });
275+ }
238276}
0 commit comments