adrenalinkin/swagger-resolver-bundle
Symfony bundle that validates request/response data against Swagger 2 (OpenAPI) specs. Generates a SwaggerResolver based on Symfony OptionsResolver, with warmed caching and debug auto-refresh. Loads docs via NelmioApiDocBundle, swagger-php, or JSON/YAML files.
Illuminate\Http\Request events) without requiring invasive changes to existing routes or middleware. Validation can be applied selectively via annotations or configuration.Validator facade or ValidatesRequests trait, but core functionality is portable.schema vs. components/schemas). Requires validation of spec compatibility during integration.swagger:watch command) to avoid stale validations.allOf, anyOf, custom formats like date-time) may need manual overrides or extensions to the bundle’s resolver.Spec Hosting Strategy:
config/swagger/) or fetched remotely (e.g., from a Git repo or API gateway)?Validation Granularity:
@SwaggerValidated)?Error Handling:
App\Exceptions\Handler)?Testing Impact:
Tooling Integration:
Validator and FormRequest classes, enabling hybrid validation (e.g., Swagger for API contracts, Laravel rules for business logic).darkaonline/l5-swagger (for OpenAPI docs) or zircote/swagger-php (for spec generation).assertJsonValidationErrors) to validate responses against specs.HttpFoundation and DependencyInjection components (already bundled with Laravel), but no additional Symfony apps needed.Phase 1: Schema Adoption
zircote/swagger-php to auto-generate specs from route annotations.config/swagger/api.yaml or a remote location (e.g., Git submodule).Phase 2: Validation Hooks
php artisan vendor:publish --provider="Adrenalinkin\SwaggerResolverBundle\SwaggerResolverBundle").Phase 3: Incremental Rollout
@SwaggerValidated annotations or route-based validation to controllers.Phase 4: CI/CD Integration
spectral or the bundle’s CLI commands) to catch schema drift early.composer.json constraints). May require adjustments for older versions (e.g., Symfony 5.x dependencies).SwaggerResolverMiddleware) doesn’t clash with existing middleware (e.g., CORS, auth) by adjusting priority in app/Http/Kernel.php.Pre-Integration:
During Integration:
Post-Integration:
swagger-codegen or custom scripts to sync specs with Laravel’s route definitions.path/to/field").php artisan swagger:dump).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Swagger spec is malformed | All dependent validations fail | Use spectral in CI to lint specs pre-deployment. |
| Remote spec fetch fails | Validation disabled for affected routes | Implement fallback to local spec cache or graceful degradation (e.g., skip validation). |
| Schema resolution timeout | Latency spikes | Set timeout limits (e.g., 200ms) and log slow resolutions. |
| Spec updates break existing tests | CI/CD pipeline failures | Use feature flags to roll out spec changes incrementally. |
| Bundle compatibility issues | Validation bypassed or errors | Maintain a fork or patch queue for critical fixes. |
How can I help you explore Laravel packages today?