Skip to content

Commit c7d8774

Browse files
committed
feat(validator): add constructor validation for negative maxErrors
Reject negative maxErrors values with InvalidArgumentException to enforce the contract that maxErrors must be 0 (unlimited) or positive.
1 parent e81f394 commit c7d8774

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/OpenApiResponseValidator.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
use const JSON_THROW_ON_ERROR;
88
use const PHP_INT_MAX;
99

10+
use InvalidArgumentException;
1011
use Opis\JsonSchema\Errors\ErrorFormatter;
1112
use Opis\JsonSchema\Validator;
1213

1314
use function array_keys;
1415
use function implode;
1516
use function json_decode;
1617
use function json_encode;
18+
use function sprintf;
1719
use function str_ends_with;
1820
use function strstr;
1921
use function strtolower;
@@ -23,7 +25,13 @@ final class OpenApiResponseValidator
2325
{
2426
public function __construct(
2527
private readonly int $maxErrors = 20,
26-
) {}
28+
) {
29+
if ($this->maxErrors < 0) {
30+
throw new InvalidArgumentException(
31+
sprintf('maxErrors must be 0 (unlimited) or a positive integer, got %d.', $this->maxErrors),
32+
);
33+
}
34+
}
2735

2836
public function validate(
2937
string $specName,

0 commit comments

Comments
 (0)