dedoc/scramble
Scramble generates up-to-date OpenAPI 3.1 API docs for Laravel automatically from your code—no PHPDoc annotations needed. Adds /docs/api UI and /docs/api.json schema routes (local by default, configurable via gate).
Pros:
#[IgnoreParam], #[SchemaName]) for granular control without verbose annotations.Cons:
darkaonline/l5-swagger.exclude config or attribute precedence).scramble.api_path filters).#[IgnoreParam] or #[Hidden] for problematic endpoints.scramble:analyze logs).#[Schema]) may require namespace qualification.securitySchemes configuration.Coverage vs. Accuracy:
CI/CD Integration:
spatie/laravel-api-tester to validate OpenAPI spec against live responses.api.json (e.g., with spectral or openapi-cli).Customization Depth:
spatie/laravel-query-builder, how to document dynamic filters?Deployment Strategy:
/docs/api be:
local)?api.json)?Tooling Ecosystem:
Laravel Core: Native support for:
required, regex).Extensions:
toResource(), toResourceCollection() (v13.19+).Non-Laravel Components:
securitySchemes or servers definitions.rebing/graphql-laravel + custom OpenAPI generation.Pilot Phase:
composer require dedoc/scramble --dev
/api/v1/users).api.json matches expected structure./docs/api.Gradual Rollout:
scramble.api_path filters to exclude legacy routes.#[IgnoreParam]) for problematic endpoints.api.json schema drifts).Legacy Handling:
scramble:analyze --dry-run to identify conflicts.#[SchemaName]).| Component | Compatibility | Mitigation |
|---|---|---|
| Laravel 10–13 | ✅ Native support | Use latest version (v0.13.28+). |
| Laravel < 10 | ⚠️ May require backports | Fork or use a maintained branch (e.g., v0.13.0). |
| Custom Validation Rules | ⚠️ Limited inference (e.g., unique:table,col) |
Extend via scramble:extend or manual attributes. |
| Non-REST APIs | ❌ (e.g., WebSockets, GraphQL) | Generate docs separately or use a hybrid approach. |
| Monolithic Apps | ⚠️ Performance may degrade with >10K routes | Use scramble.api_path to scope analysis. |
Pre-requisites:
Installation:
composer require dedoc/scramble
php artisan scramble:install
viewApiDocs gate in App\Providers\AuthServiceProvider if needed.Configuration:
config/scramble.php for:
api_path: Filter routes (e.g., ['prefix' => 'api/v1']).cache: Enable true for performance.php artisan vendor:publish --provider="Dedoc\Scramble\ScrambleServiceProvider"
Validation:
/docs/api locally.api.json with a golden copy (e.g., using diff or CI checks).CI Integration:
# .github/workflows/docs.yml
- name: Validate API Docs
run: |
curl -s http://localhost/docs/api.json | jq . > generated.json
git diff --exit-code -- docs/golden.json generated.json
Pros:
#[IgnoreParam] on a single method).Cons:
scramble.php settings may need updates across environments.How can I help you explore Laravel packages today?