Skip to content

Commit e81f394

Browse files
committed
docs(readme): add maxErrors parameter documentation
1 parent 17d8993 commit e81f394

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ This creates `config/openapi-contract-testing.php`:
8080
```php
8181
return [
8282
'default_spec' => '', // e.g., 'front'
83+
84+
// Maximum number of validation errors to report per response.
85+
// 0 = unlimited (reports all errors).
86+
'max_errors' => 20,
8387
];
8488
```
8589

@@ -140,6 +144,23 @@ $result = $validator->validate(
140144
$this->assertTrue($result->isValid(), $result->errorMessage());
141145
```
142146

147+
#### Controlling the number of validation errors
148+
149+
By default, up to **20** validation errors are reported per response. You can change this via the constructor:
150+
151+
```php
152+
// Report up to 5 errors
153+
$validator = new OpenApiResponseValidator(maxErrors: 5);
154+
155+
// Report all errors (unlimited)
156+
$validator = new OpenApiResponseValidator(maxErrors: 0);
157+
158+
// Stop at first error (original behavior)
159+
$validator = new OpenApiResponseValidator(maxErrors: 1);
160+
```
161+
162+
For Laravel, set the `max_errors` key in `config/openapi-contract-testing.php`.
163+
143164
## Coverage Report
144165

145166
After running tests, the PHPUnit extension prints a coverage report:
@@ -211,9 +232,12 @@ The package auto-detects the OAS version from the `openapi` field and handles sc
211232

212233
Main validator class. Validates a response body against the spec.
213234

235+
The constructor accepts a `maxErrors` parameter (default: `20`) controlling how many schema errors are collected before stopping. Use `0` for unlimited, `1` to stop at the first error.
236+
214237
The optional `responseContentType` parameter enables content negotiation: when provided, non-JSON content types (e.g., `text/html`) are checked for spec presence only, while JSON-compatible types proceed to full schema validation.
215238

216239
```php
240+
$validator = new OpenApiResponseValidator(maxErrors: 20);
217241
$result = $validator->validate(
218242
specName: 'front',
219243
method: 'GET',

0 commit comments

Comments
 (0)