Skip to content

Commit dff0573

Browse files
simplify code for maxContains, minContains
1 parent 8ef2673 commit dff0573

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

lib/JSON/Schema/Draft201909/Vocabulary/Applicator.pm

+6-10
Original file line numberDiff line numberDiff line change
@@ -373,19 +373,15 @@ sub _eval_keyword_contains {
373373
return 0 if $state->{short_circuit};
374374
}
375375

376-
if (exists $schema->{maxContains}) {
377-
local $state->{keyword} = 'maxContains';
378-
379-
if ($num_valid > $schema->{maxContains}) {
380-
$valid = 0;
381-
E($state, 'contains too many matching items');
382-
return 0 if $state->{short_circuit};
383-
}
376+
# TODO: in the future, we can move these implementations to the Validation vocabulary
377+
# and inspect the annotation produced by the 'contains' keyword.
378+
if (exists $schema->{maxContains} and $num_valid > $schema->{maxContains}) {
379+
$valid = E({ %$state, keyword => 'maxContains' }, 'contains too many matching items');
380+
return 0 if $state->{short_circuit};
384381
}
385382

386383
if ($num_valid < ($schema->{minContains} // 1)) {
387-
$valid = 0;
388-
E({ %$state, keyword => 'minContains' }, 'contains too few matching items');
384+
$valid = E({ %$state, keyword => 'minContains' }, 'contains too few matching items');
389385
return 0 if $state->{short_circuit};
390386
}
391387

0 commit comments

Comments
 (0)