mermade/openapi3-examples
PHP package for working with OpenAPI 3 example objects: generate, load and manage request/response examples, helping you enrich specs and keep sample payloads in sync during API development, docs and testing workflows.
Purpose Alignment: The package is a test suite for OpenAPI 3.x validators, not a production-ready library. It provides predefined test cases (passing/failing) to validate OpenAPI 3.x compliance in tools like Swagger, Spectral, or custom validators.
Modularity:
PHP/Laravel Compatibility:
zircote/swagger-php, darkaonline/l5-swagger).spatie/laravel-openapi).openapi.yaml files before merging.Dependencies:
zircote/swagger-php (PHP-based).openapi-tools/openapi-generator (Java-based, but can be called via CLI).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Validator Dependency | Medium | Adopt a widely used validator (e.g., zircote/swagger-php) with existing Laravel support. |
| Test Case Relevance | Low | Review test cases to ensure they cover edge cases for your API specs. |
| Performance Overhead | Low | Test cases are lightweight; minimal runtime impact. |
| False Positives/Negatives | Medium | Validate against a subset of test cases first to ensure alignment with your OpenAPI usage. |
| Maintenance Burden | Low | Package is stable (Apache 2.0 license); updates likely infrequent. |
Why validate OpenAPI specs?
Validator Library Choice
zircote/swagger-php or a custom solution?"Integration Scope
Test Case Customization
Error Handling
Scaling
| Component | Compatibility | Notes |
|---|---|---|
| PHP/Laravel | ✅ High | Native PHP package; works with Laravel’s dependency injection. |
| OpenAPI Validators | ✅ High | Compatible with zircote/swagger-php, spectral (via CLI), etc. |
| CI/CD (GitHub Actions, GitLab CI) | ✅ High | Easy to add as a step (e.g., composer test). |
| API Gateways (Kong, Apigee) | ⚠️ Medium | Requires validator integration (e.g., plugin or pre-deployment check). |
| Documentation Tools (Swagger UI, Redoc) | ✅ High | Validate specs before rendering. |
| Custom Middleware | ✅ High | Can be wrapped in Laravel middleware for runtime checks. |
Assessment Phase (1-2 days)
zircote/swagger-php).composer require --dev mermade/openapi3-examples
Pilot Integration (3-5 days)
git push:
// tests/OpenAPIValidationTest.php
use Mermade\OpenApi3Examples\TestCases;
use Zircote\Swagger\Scanner;
public function testOpenApiSpec()
{
$validator = new Scanner();
$result = $validator->scan('api/openapi.yaml');
$this->assertTrue($result->isValid(), "OpenAPI spec is invalid!");
}
composer test
// app/Http/Middleware/ValidateOpenApi.php
public function handle($request, Closure $next)
{
$validator = new Scanner();
$result = $validator->scan(base_path('api/openapi.yaml'));
if (!$result->isValid()) {
abort(500, "OpenAPI spec validation failed: " . $result->getErrors());
}
return $next($request);
}
app/Http/Kernel.php.Full Rollout (1 week)
x- fields. Action: Extend test suite or whitelist extensions.Package Updates:
composer.json if stability is critical.Test Case Updates:
Validator Library:
zircote/swagger-php).How can I help you explore Laravel packages today?