laraswag/laravel-swagger-exporter
最新稳定版本:v1.0.0
Composer 安装命令:
composer require laraswag/laravel-swagger-exporter
包简介
A small Laravel package to export model-based Swagger YAML files and provide a simple Swagger UI view.
README 文档
README
Automatically generate Swagger/OpenAPI YAML documentation for your Eloquent models by analyzing routes and FormRequest validation rules.
Installation
composer require laraswag/laravel-swagger-exporter
The package auto-registers with Laravel 11+. For Laravel 10 and below, add the service provider to config/app.php:
'providers' => [ // ... Laraswag\LaravelSwaggerExporter\ServiceProvider::class, ],
Quick Usage
Generate Swagger Files
# Export a single model php artisan swagger:export --model=Post # Or use FQCN php artisan swagger:export --model=App\\Models\\Post # Or Export all models php artisan swagger:export --all
View Documentation
Visit /swagger in your app to view all generated YAML files.
Features
- Automatic Documentation: Analyzes routes and FormRequest validation to generate Swagger YAML
- Built-in UI: View generated docs at
/swagger - Artisan Commands: Easy model export via CLI
- Configurable: Customize output paths and routes via
config/laraswag.php - DI Ready: Use
ModelSwaggerExporterservice directly
Publishing Assets
# Publish public files php artisan vendor:publish --provider="Laraswag\LaravelSwaggerExporter\ServiceProvider" --tag=laraswag-public # Publish config php artisan vendor:publish --provider="Laraswag\LaravelSwaggerExporter\ServiceProvider" --tag=laraswag-config # Publish views for customization php artisan vendor:publish --provider="Laraswag\LaravelSwaggerExporter\ServiceProvider" --tag=laraswag-views
Routes
add these routes to api.php file
Route::get('/ping', fn () => response()->json(['message' => 'pong'], 200)); Route::middleware('auth:sanctum')->get('/ping-auth', fn () => response()->json(['message' => 'pong'], 200));
Configuration
Key options in config/laraswag.php:
'public_path' => public_path('swagger_ui/'), // Where YAML files are stored 'route_prefix' => 'swagger', // URL prefix for the UI 'middleware' => ['web'], // Middleware for Swagger routes
Requirements
- PHP 8.0+
- Laravel 8.x, 9.x, 10.x, or 11.x
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-23