Skip to content

Commit 4404bd0

Browse files
authored
Merge pull request #24 from studio-design/docs/readme-content-negotiation
docs(readme): add content negotiation documentation
2 parents f89ef5c + f85051f commit 4404bd0

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Validate your API responses against your OpenAPI specification during testing, a
1212

1313
- **OpenAPI 3.0 & 3.1 support** — Automatic version detection from the `openapi` field
1414
- **Response validation** — Validates response bodies against JSON Schema (Draft 07 via opis/json-schema). Supports `application/json` and any `+json` content type (e.g., `application/problem+json`)
15+
- **Content negotiation** — Accepts the actual response `Content-Type` to handle mixed-content specs. Non-JSON responses (e.g., `text/html`, `application/xml`) are verified for spec presence without body validation; JSON-compatible responses are fully schema-validated
1516
- **Endpoint coverage tracking** — Unique PHPUnit extension that reports which spec endpoints are covered by tests
1617
- **Path matching** — Handles parameterized paths (`/pets/{petId}`) with configurable prefix stripping
1718
- **Laravel adapter** — Optional trait for seamless integration with Laravel's `TestResponse`
@@ -133,6 +134,7 @@ $result = $validator->validate(
133134
requestPath: '/api/v1/pets',
134135
statusCode: 200,
135136
responseBody: $decodedJsonBody,
137+
responseContentType: 'application/json', // optional: enables content negotiation
136138
);
137139

138140
$this->assertTrue($result->isValid(), $result->errorMessage());
@@ -209,13 +211,16 @@ The package auto-detects the OAS version from the `openapi` field and handles sc
209211

210212
Main validator class. Validates a response body against the spec.
211213

214+
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.
215+
212216
```php
213217
$result = $validator->validate(
214218
specName: 'front',
215219
method: 'GET',
216220
requestPath: '/api/v1/pets/123',
217221
statusCode: 200,
218222
responseBody: ['id' => 123, 'name' => 'Fido'],
223+
responseContentType: 'application/json',
219224
);
220225
221226
$result->isValid(); // bool

0 commit comments

Comments
 (0)