darkaonline/l5-swagger
Laravel-friendly wrapper around swagger-php and Swagger UI. Generate and serve OpenAPI/Swagger docs from annotations, with configurable routes, UI, and assets. Includes install/config guides, migration notes, tips, and Passport auth examples.
Pros:
#[OpenApi\...]) for declarative API documentation, reducing boilerplate and improving maintainability.Cons:
swagger-php: Underlying library (zircote/swagger-php) is a wrapper around OpenAPI specs but lacks native Laravel optimizations (e.g., Eloquent model introspection). May require manual overrides for complex schemas.Laravel Ecosystem Compatibility:
securitySchemes. Custom auth schemes require manual configuration.L5Swagger\Testing\TestsOpenApi).Non-Laravel Dependencies:
High:
generate_always: false) mitigates this but requires manual cache management.swagger-php and swagger-ui for CVEs.Medium:
#[Route]).L5_SWAGGER_UI_ASSETS_PATH) may break if not configured correctly, especially in Dockerized or CDN-hosted environments.Low:
#[OpenApi\Info] + route annotations).API Maturity:
Team Expertise:
darkaonline/l5-swagger v9.x for PHP 7.x).Tooling Integration:
Performance:
Customization Needs:
swagger-php processors.CI/CD Impact:
openapi-linter or spectral can integrate with Laravel tests.Alternatives:
spatie/laravel-openapi, zircote/swagger-php standalone) been evaluated? Justify choice based on Laravel-specific features (e.g., route introspection).Laravel-Centric:
/api/documentation), publishes config (l5-swagger.php), and binds facades (e.g., Swagger). Integrates with Laravel’s event system (e.g., booted).#[OpenApi\Tag] or manual route mapping. Supports API resource grouping.config/l5-swagger.php with environment variable overrides (e.g., L5_SWAGGER_UI_DOC_EXPANSION). Supports dark mode, asset paths, and auth schemes.OpenAPI/Swagger Stack:
swagger-php to parse PHP attributes (e.g., #[OpenApi\Info], #[OpenApi\RequestBody]) into OpenAPI 3.x YAML/JSON.ui.specs array.securitySchemes configuration.Testing:
L5Swagger\Testing\TestsOpenApi trait for validating specs in PHPUnit.vireo/vireo or pactphp/pact for API consumer/provider validation.| Phase | Action Items | Risks | Mitigation |
|---|---|---|---|
| Pre-Integration | 1. Audit Laravel version (target PHP 8.2+, Laravel 11+). | Legacy stack incompatibility. | Upgrade path planning; consider darkaonline/l5-swagger v9.x for older PHP. |
| 2. Inventory existing API documentation (Markdown, Postman collections, etc.). | Documentation duplication. | Deprecate legacy docs post-migration; use OpenAPI as single source of truth. | |
| 3. Evaluate authentication schemes (Passport/Sanctum/JWT). | Custom auth schemes unsupported. | Plan for manual securitySchemes configuration or extension. |
|
| Pilot Integration | 4. Install package: composer require darkaonline/l5-swagger. |
Dependency conflicts. | Test in isolation; resolve via composer.json overrides or package patches. |
5. Publish config: php artisan vendor:publish --provider="L5Swagger\L5SwaggerServiceProvider". |
Misconfiguration. | Start with default config; customize incrementally. | |
6. Annotate a single controller (e.g., UserController) with basic #[OpenApi\...] attributes. |
Incorrect spec generation. | Validate output at /api/documentation; use openapi-linter in CI. |
|
| Full Rollout |
How can I help you explore Laravel packages today?