定制 martinpham/laravel-openapi-generator 二次开发

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

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

martinpham/laravel-openapi-generator

最新稳定版本:v1.0.0

Composer 安装命令:

composer require martinpham/laravel-openapi-generator

包简介

Generate OpenAPI specification from Laravel routes and Laravel Eloquent/Laravel Data objects.

README 文档

README

This is a fork of https://github.com/xolvionl/laravel-data-openapi-generator with newer Laravel, Spartie Data, and Eloquent model supports

Generate OpenAPI specification from Laravel routes and Laravel Eloquent models & Spartie Data classes

Install

composer require martinpham/laravel-openapi-generator

Config

php artisan vendor:publish --tag=openapi-generator

Generate

php artisan openapi:generate

SwaggerUI

SwaggerUI will be available at /api/openapi

Example

<?php  
namespace App\Data;  
  
use App\Models\User;  
use Spatie\LaravelData\Data;  
  
class GreetingData extends Data  
{  
    public function __construct(  
        public User         $user,  
        public string       $message  
    ){}  
}  
<?php
namespace App\Http\Controllers\Api;  

use Spatie\RouteAttributes\Attributes\Get;
use Spatie\RouteAttributes\Attributes\Group;
use App\Data\GreetingData;
use App\Http\Controllers\Controller;
use Illuminate\Database\Eloquent\Collection;
use App\Models\User;

#[Group('/play', as: 'play')]
class PlaygroundApiController extends Controller
{  
    #[Get('/who-is/{user}', name: ".whois")]
    public function hello(User $user): User
    {
        return $user;
    }

    
    #[Get('/user', name: ".user")]
    /** @return Collection<int, User> */
    public function hello(): Collection
    {
        return User::all();
    }

    #[Get('/hello/{user}', name: ".hello")]
    public function hello(User $user): GreetingData
    {
        return GreetingData::from($user, "hello ${user->name}");
    }
}

Results https://imgur.com/a/Mt3qa51

统计信息

  • 总下载量: 40
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-04