A Laravel package to generate API documentation from controller annotations
alagiesinghateh/laravel-docmaker is a Laravel package for a laravel package to generate api documentation from controller annotations.
It currently has 0 GitHub stars and 10 downloads on Packagist (latest version v0.1.0).
Install it with composer require alagiesinghateh/laravel-docmaker.
Discover more Laravel packages by alagiesinghateh
or browse all Laravel packages to compare alternatives.
Last updated
A powerful Laravel package that automatically generates comprehensive API documentation from your controller annotations. Supports API Blueprint format with intelligent annotation parsing, authentication detection, and smart backup system.
@api annotations for your controller methodsInstall via Composer:
composer require alagiesinghateh/laravel-docmaker
Publish the configuration file:
php artisan vendor:publish --provider="Alagiesinghateh\LaravelApiDocGenerator\ApiDocGeneratorServiceProvider" --tag="config"
Publish the views (optional):
php artisan vendor:publish --provider="Alagiesinghateh\LaravelApiDocGenerator\ApiDocGeneratorServiceProvider" --tag="views"
After publishing the config file, you can modify config/api-doc-generator.php:
return [
'output_dir' => storage_path('docs/api'),
'controller_paths' => [
app_path('Http/Controllers/API'),
app_path('Http/Controllers/Api'),
],
'web_interface' => [
'enabled' => true,
'route_prefix' => 'api-docs',
'middleware' => ['web', 'api-docs'],
],
'security' => [
'ip_whitelist' => ['127.0.0.1', '::1'],
'restricted_paths' => [],
],
'allowed_users' => [],
'middleware' => [
'detect' => true,
'auth_middleware' => ['auth', 'auth:api', 'auth:sanctum'],
'security_schemes' => [
'auth' => 'bearer',
'auth:api' => 'bearer',
'auth:sanctum' => 'bearer',
],
'exclude' => ['web', 'throttle', 'bindings'],
],
'backup' => [
'max_backups' => 10,
],
'defaults' => [
'method' => 'GET',
'path' => '/api/endpoint',
'name' => 'Untitled Endpoint',
'group' => 'General',
],
];
# Generate documentation from controller annotations
php artisan singhateh:generate
# Force regenerate all annotations (even existing ones)
php artisan singhateh:generate --force
# Dry run (see what would change without modifying files)
php artisan singhateh:generate --dry-run
# Regenerate annotations for all controllers
php artisan singhateh:annotate:regenerate
# Regenerate for specific directory
php artisan singhateh:annotate:regenerate --path=Http/Controllers/API
# Cross-check without modifying files
php artisan singhateh:annotate:regenerate --cross-check
# Force regenerate all annotations
php artisan singhateh:annotate:regenerate --force
# List available backups
php artisan singhateh:backups:list
# Restore from latest backup
php artisan singhateh:backups:restore
# Restore specific backup
php artisan singhateh:backups:restore filename=api-docs_2023-12-15_143022.json
/**
* @api {GET} /api/users Get Users
* @apiName GetUsers
* @apiGroup User
* @apiDescription Retrieve a list of all users
*
* @apiParam {String} [page] Optional page number
* @apiParam {String} [per_page] Optional items per page
*
* @apiSuccess {Object[]} data Array of users
* @apiSuccess {Number} data.id User ID
* @apiSuccess {String} data.name User name
* @apiSuccess {String} data.email User email
*
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
* "data": [
* {
* "id": 1,
* "name": "John Doe",
* "email": "john@example.com"
* }
* ]
* }
*
* @apiErrorExample {json} Error-Response:
* HTTP/1.1 500 Internal Server Error
* {
* "error": "Server error occurred"
* }
*/
public function index()
{
// Controller logic
}
| Annotation | Description | Example |
|------------------|-------------------------|-------------------------------------------|
| @api | HTTP method and endpoint | @api {GET} /api/users Get Users |
| @apiName | Endpoint name | @apiName GetUsers |
| @apiGroup | Group/category | @apiGroup User |
| @apiDescription| Endpoint description | @apiDescription Get all users |
| @apiParam | Request parameter | @apiParam {String} name User name |
| @apiHeader | Request header | @apiHeader {String} Authorization Bearer token |
| @apiSuccess | Success response field | @apiSuccess {Number} id User ID |
| @apiError | Error response | @apiError {401} Unauthorized |
| @apiAuth | Authentication type | @apiAuth bearer |
| @apiMiddleware | Middleware used | @apiMiddleware auth:api |
| @apiPermission | Required permissions | @apiPermission users.read,users.write |
The package includes built-in security features:
// config/api-doc-generator.php
'security' => [
'ip_whitelist' => ['192.168.1.100', '10.0.0.0/24'],
'restricted_paths' => ['internal', 'admin'],
],
'allowed_users' => [
'[email protected]',
'[email protected]',
],
class UserController extends Controller
{
public static $apiParams = [
'custom_param' => [
'type' => 'string',
'required' => true,
'description' => 'Custom parameter description',
],
];
}
/**
* @api {POST} /api/users Create User
* @apiName CreateUser
* @apiGroup User
* @apiDescription Create a new user account
*
* @apiParam {String} name User's full name
* @apiParam {String} email User's email address
* @apiParam {String} password User's password
*
* @apiAuth bearer
* @apiMiddleware auth:api
*/
public function store(CreateUserRequest $request)
{
// Your controller logic
}
class CreateUserRequest extends FormRequest
{
public function rules()
{
return [
'name' => 'required|string|max:255',
'email' => 'required|email|unique:users',
'password' => 'required|min:8|confirmed',
];
}
}
Access the web interface at:
http://your-app.com/api-docs
![API Documentation Interface]
Publish the views and modify them as needed:
php artisan vendor:publish --provider="Alagiesinghateh\LaravelApiDocGenerator\ApiDocGeneratorServiceProvider" --tag="views"
Views will be published to:
resources/views/vendor/api-doc-generator/
The package includes a smart backup system:
Run the package tests:
composer test
We welcome contributions! Please see CONTRIBUTING.md for details.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)This package is open-source software licensed under the MIT license.
If you discover any bugs, please create an issue on GitHub.
For support and questions:
Note: This package is actively maintained. For the latest updates and features, always check the GitHub repository.