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
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.
- 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
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/docsThat's it! 🎉 Your API is now fully documented.
The generated JSON is compatible with all major API clients:
# Get the raw OpenAPI JSON
curl http://your-app-url/docs.jsonImport 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
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.
| Before | After |
|---|---|
| ❌ No documentation ❌ Manual maintenance ❌ Outdated docs |
✅ Beautiful Swagger UI ✅ Auto-generated from code ✅ Always up-to-date |
- Modern, responsive design
- Interactive "Try it out" functionality
- Professional API explorer
- Mobile-friendly interface
- Auto-detects your routes, validation, and auth
- Stays in sync with your code changes
- No annotations to maintain
- Regenerate with one command
- Configurable authentication
- CORS handling included
- Error handling built-in
- Laravel-native integration
| 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 |
- PHP 8.1+
- Laravel 10.0+
composer require provydon/docs-generatephp artisan vendor:publish --tag=docs-generateThis creates:
config/docs-generate.php- Configuration fileresources/views/vendor/docs-generate/- Swagger UI view
php artisan docs:generateNavigate to: http://your-app-url/docs
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.comThe package automatically detects authentication requirements by checking for these middleware:
authauth:sanctumauth:apisanctum- Any middleware containing
Authenticate
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.jsonEdit 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',
],
],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
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)
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
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
Automatically adds security requirements if route has:
authmiddlewareauth:sanctummiddlewareauth:apimiddlewaresanctummiddleware- Any middleware containing
Authenticate
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"}
}
}
}
}
}
}
}
}
}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"}
}
}php artisan docs:generateGenerates fresh API documentation from your current routes and controllers.
Make sure you've run:
php artisan docs:generateCheck that routes have the api/ prefix:
'route_filters' => [
'prefix' => 'api/',
],Clear route cache:
php artisan route:clear
php artisan route:cacheContributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
If this package helped you, consider buying me a coffee to support development!
Made with ❤️ by Provydon
