provydon / docs-generate
Automatic API documentation for your Laravel app โ zero annotations, OpenAPI 3.0 JSON & Swagger UI.
Installs: 1 863
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/provydon/docs-generate
Requires
- php: ^8.1
- illuminate/console: ^9.0|^10.0|^11.0|^12.0
- illuminate/http: ^9.0|^10.0|^11.0|^12.0
- illuminate/routing: ^9.0|^10.0|^11.0|^12.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
- illuminate/validation: ^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- mockery/mockery: ^1.4
- orchestra/testbench: ^7.0|^8.0|^9.0
- phpunit/phpunit: ^9.5|^10.0
README
๐ Docs Generate
Automatic API documentation for your Laravel app โ no annotations or doc blocks needed, OpenAPI 3.0 JSON & Swagger UI.
Generate beautiful API documentation automatically from your existing Laravel code
โจ Why Docs Generate?
Stop writing documentation manually! This package automatically generates beautiful Swagger/OpenAPI documentation from your existing Laravel codeโno annotations, no code pollution, no maintenance headaches.
๐ฏ Perfect For:
- Laravel APIs that need professional documentation
- Teams who want docs that stay in sync with code
- Developers who hate writing documentation
- Projects that need client-ready API docs
๐ Quick Start
Get documented instantly:
# 1. Install composer require provydon/docs-generate # 2. Publish config php artisan vendor:publish --tag=docs-generate # 3. Generate docs (instant!) php artisan docs:generate # 4. View your beautiful docs # Visit: http://your-app-url/docs
That's it! ๐ Your API is now fully documented.
๐ Use with Any API Client
The generated JSON is compatible with all major API clients:
# Get the raw OpenAPI JSON
curl http://your-app-url/docs.json
Import into your favorite tools:
- ๐ฎ Postman - Import OpenAPI 3.0 JSON
- ๐ Insomnia - Import OpenAPI spec
- ๐ Thunder Client - VS Code extension
- ๐ฅ Bruno - Open-source API client
- ๐ฑ Any OpenAPI-compatible tool
Code changes โ run command โ docs automatically reflect changes
๐ Documentation Stays in Sync
The best part? Your documentation automatically stays up-to-date with your code:
- Make code changes โ Add new routes, update controllers, modify validation
- Run
php artisan docs:generateโ Regenerates the documentation - Deploy your code โ Documentation file goes with your code
- Documentation is always current โ No manual updates needed!
The docs.json file lives in your public/ folder, so it's part of your project and gets deployed with every code update. Your API documentation will always reflect your latest code changes.
๐งฑ Always Auto Update Your Documentation
Add php artisan docs:generate to your deployment script or build pipeline so every release ships with freshly generated docs:
add php artisan docs:generate to ur deployment script or in ur build pipeline
You can even surface the progress logs in your CI/CD output:
๐ Generating API documentation...
Found 81 API routes
โ
API documentation generated successfully!
๐ Output: /app/public/docs.json
๐ View at: https://fikets.com/docs
โจ What You Get
| Before | After |
|---|---|
| โ No documentation โ Manual maintenance โ Outdated docs |
โ
Beautiful Swagger UI โ Auto-generated from code โ Always up-to-date |
๐จ Beautiful Swagger UI
- Modern, responsive design
- Interactive "Try it out" functionality
- Professional API explorer
- Mobile-friendly interface
๐ Zero Maintenance
- Auto-detects your routes, validation, and auth
- Stays in sync with your code changes
- No annotations to maintain
- Regenerate with one command
๐ก๏ธ Production Ready
- Configurable authentication
- CORS handling included
- Error handling built-in
- Laravel-native integration
๐ฏ Key Features
| Feature | Description |
|---|---|
| ๐ซ Zero Annotations | No code pollutionโworks with existing code |
| ๐ Smart Detection | Auto-detects routes, validation, and auth |
| ๐ Inline Validation | Supports $request->validate() calls |
| ๐จ Beautiful UI | Modern Swagger UI with "Try it out" |
| ๐ Auth Ready | Built-in authentication support |
| โ๏ธ Fully Configurable | Customize everything via config |
| ๐ Laravel Native | Uses Laravel conventions and patterns |
๐ Requirements
- PHP 8.1+
- Laravel 10.0+
๐ ๏ธ Installation
Step 1: Install via Composer
composer require provydon/docs-generate
Step 2: Publish Configuration
php artisan vendor:publish --tag=docs-generate
This creates:
config/docs-generate.php- Configuration fileresources/views/vendor/docs-generate/- Swagger UI view
Step 3: Generate Documentation
php artisan docs:generate
Step 4: View Your Documentation
Navigate to: http://your-app-url/docs
๐จ Authentication
Documentation Access Control
Control who can access your API documentation:
# No authentication (default) DOCS_AUTH_ENABLED=false # Authenticated users only DOCS_AUTH_ENABLED=true DOCS_AUTH_TYPE=authenticated # Specific emails only DOCS_AUTH_ENABLED=true DOCS_AUTH_TYPE=specific_emails DOCS_AUTH_ALLOWED_EMAILS=admin@example.com,developer@example.com
API Authentication Detection
The package automatically detects authentication requirements by checking for these middleware:
authauth:sanctumauth:apisanctum- Any middleware containing
Authenticate
โ๏ธ Configuration
Route Configuration
Customize your documentation routes:
# Enable/disable route registration (default: true) DOCS_ROUTES_ENABLED=true # Customize documentation path (default: /docs) DOCS_PATH=/api-docs # Customize JSON path (default: /docs.json) DOCS_JSON_PATH=/api-docs.json
API Information
Edit config/docs-generate.php:
'info' => [ 'title' => env('APP_NAME', 'Laravel API'), 'description' => 'API Documentation automatically generated', 'version' => '1.0.0', 'contact' => [ 'name' => 'API Support', 'email' => 'support@example.com', ], ],
๐ Output File
The generated API documentation is saved as public/docs.json in your Laravel project. This approach offers several benefits:
- Always Accessible: File is in the public folder, accessible via web server
- Stays with Code: Documentation file is part of your project and version controlled
- Auto-Updates: Latest docs automatically follow code updates when you deploy
- Part of Project: Included in version control and deployments
- CDN Ready: Can be served via CDN for better performance
- Simple: No complex storage configuration needed
Direct Access:
https://your-app.com/docs.json
Via Route (with error handling):
https://your-app.com/docs.json
๐ง How It Works
1. Route Analysis
Scans all Laravel routes with the api/ prefix and extracts:
- HTTP methods (GET, POST, PUT, DELETE, etc.)
- URI patterns and parameters
- Controller and method names
- Applied middleware (for auth detection)
2. Validation Extraction
For each route, it inspects the controller method:
- Identifies FormRequest classes in method parameters
- Detects inline
$request->validate()calls in method body - Extracts validation rules from both sources
- Converts rules to OpenAPI schema definitions
3. Smart Type Detection
Based on field names and validation rules, it automatically detects:
emailfields โ format: emailpasswordfields โ format: password, minLength: 8phonefields โ format: phoneurlfields โ format: uridatefields โ format: dateuuidfields โ format: uuidimage/filefields โ format: binary
4. Authentication Detection
Automatically adds security requirements if route has:
authmiddlewareauth:sanctummiddlewareauth:apimiddlewaresanctummiddleware- Any middleware containing
Authenticate
๐ Examples
Example 1: FormRequest Validation
Laravel Code:
Route::post('/api/users', [UserController::class, 'store']) ->middleware('auth:sanctum'); class StoreUserRequest extends FormRequest { public function rules() { return [ 'name' => 'required|string|max:255', 'email' => 'required|email|unique:users', 'password' => 'required|string|min:8', 'phone' => 'nullable|string', ]; } }
Generated Swagger:
{
"paths": {
"/api/users": {
"post": {
"tags": ["Users"],
"summary": "Create a new User",
"security": [{"sanctum": []}],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": ["name", "email", "password"],
"properties": {
"name": {"type": "string", "maxLength": 255},
"email": {"type": "string", "format": "email"},
"password": {"type": "string", "format": "password", "minLength": 8},
"phone": {"type": "string", "format": "phone"}
}
}
}
}
}
}
}
}
}
Example 2: Inline Validation
Laravel Code:
Route::post('/api/otp/verify', [OtpController::class, 'verify']); class OtpController extends Controller { public function verify(Request $request) { $validated = $request->validate([ 'user_id' => 'required|integer|exists:users,id', 'otp' => 'required|string|digits:6', 'verified' => 'nullable|boolean', ]); } }
Generated Swagger:
{
"properties": {
"user_id": {"type": "integer", "description": "Must exist in users"},
"otp": {"type": "string", "pattern": "^[0-9]{6}$", "minLength": 6, "maxLength": 6},
"verified": {"type": "boolean"}
}
}
๐ Commands
Generate Documentation
php artisan docs:generate
Generates fresh API documentation from your current routes and controllers.
๐ ๏ธ Troubleshooting
Documentation not showing?
Make sure you've run:
php artisan docs:generate
Routes not appearing?
Check that routes have the api/ prefix:
'route_filters' => [ 'prefix' => 'api/', ],
404 on /docs?
Clear route cache:
php artisan route:clear php artisan route:cache
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
โ Support
If this package helped you, consider buying me a coffee to support development!
Made with โค๏ธ by Provydon
โญ Star on GitHub โข ๐ Report Bug โข ๐ก Request Feature
