定制 laraswag/laravel-swagger-exporter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

Latest Version on Packagist License PHP Version Laravel Version

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 ModelSwaggerExporter service 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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固