定制 nutandc/laravel-postman-generator 二次开发

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

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

nutandc/laravel-postman-generator

Composer 安装命令:

composer require nutandc/laravel-postman-generator

包简介

Laravel Postman & OpenAPI Generator — auto-create Postman collections and OpenAPI 3.0 docs from Laravel routes with smart grouping, examples, and environment files.

README 文档

README

CI Latest Version Total Downloads License

Laravel Postman & OpenAPI Generator — auto-create Postman collections and OpenAPI 3.0 docs from Laravel routes with smart grouping, examples, and environment files.

Features

  • Auto-scan Laravel routes
  • Postman v2.1 collection output
  • OpenAPI 3.0 JSON output
  • Route metadata via PHP attributes
  • FormRequest rule parsing for body/query examples
  • Group routes into folders (by URI, name, or tag)
  • Auth support (bearer, api key, basic)
  • Default headers and sample payloads
  • Postman variables for base URL and tokens
  • Postman environment output
  • Response examples via attributes/overrides or auto from request rules
  • Extensible metadata providers
  • Configurable output paths

Requirements

  • PHP 8.2+
  • Laravel 10/11/12

Installation

composer require nutandc/laravel-postman-generator

Publish config:

php artisan vendor:publish --tag=postman-generator-config

Copy .env.example keys into your Laravel .env file and update as needed.

Usage

Generate both outputs:

php artisan postman:generate

Generate only one format:

php artisan postman:generate --format=postman
php artisan postman:generate --format=openapi

Attribute Example

use Nutandc\PostmanGenerator\Attributes\EndpointDoc;

#[EndpointDoc(
    summary: 'List users',
    tags: ['Users'],
    auth: 'bearer',
    headers: [
        ['name' => 'X-Request-ID', 'value' => '{{request_id}}', 'required' => false],
    ],
    query: [
        ['name' => 'page', 'type' => 'integer', 'required' => false, 'example' => 2],
    ],
    responses: [
        ['status' => 200, 'description' => 'OK', 'body' => ['data' => ['id' => 1]]],
    ],
)]
public function index() {}

Route Grouping

By default routes are grouped into folders by the first URI segment (e.g., api/users -> users). You can change grouping strategy in config:

'postman' => [
    'grouping' => [
        'strategy' => 'name', // uri | name | none
        'name_separator' => '.',
        'uri_depth' => 1,
        'strip_prefixes' => ['api'],
        'fallback' => 'General',
    ],
],

To remove debug routes (debugbar/clockwork/log-viewer), use scan filters:

'scan' => [
    'include_prefixes' => ['api'],
    'exclude_prefixes' => ['_debugbar', '__clockwork', 'log-viewer'],
    'exclude_route_names' => ['debugbar.', 'clockwork.', 'log-viewer.'],
],

Config Highlights

return [
    'base_url' => env('POSTMAN_GENERATOR_BASE_URL', env('APP_URL', 'http://localhost')),
    'headers' => [
        'default' => [
            ['name' => env('POSTMAN_GENERATOR_HEADER_ACCEPT_NAME', 'Accept'), 'value' => env('POSTMAN_GENERATOR_HEADER_ACCEPT_VALUE', 'application/json')],
        ],
        'json' => [
            ['name' => env('POSTMAN_GENERATOR_HEADER_CONTENT_TYPE_NAME', 'Content-Type'), 'value' => env('POSTMAN_GENERATOR_HEADER_CONTENT_TYPE_VALUE', 'application/json'), 'required' => true],
        ],
    ],
    'output' => [
        'path' => storage_path('app/postman'),
    ],
    'scan' => [
        'form_request' => [
            'enabled' => env('POSTMAN_GENERATOR_FORM_REQUEST_ENABLED', true),
        ],
    ],
    'metadata_providers' => [
        \Nutandc\PostmanGenerator\Metadata\Providers\FormRequestMetadataProvider::class,
        \Nutandc\PostmanGenerator\Metadata\Providers\AttributeMetadataProvider::class,
        \Nutandc\PostmanGenerator\Metadata\Providers\OverridesMetadataProvider::class,
    ],
    'auth' => [
        'default' => 'bearer',
    ],
    'responses' => [
        'auto_from_request' => env('POSTMAN_GENERATOR_RESPONSE_AUTO_FROM_REQUEST', true),
        'default_status' => env('POSTMAN_GENERATOR_RESPONSE_DEFAULT_STATUS', 200),
        'default_description' => env('POSTMAN_GENERATOR_RESPONSE_DEFAULT_DESCRIPTION', 'OK'),
    ],
    'postman' => [
        'use_base_url_variable' => true,
        'variables' => [
            'base_url' => env('POSTMAN_GENERATOR_POSTMAN_BASE_URL'),
            'token' => env('POSTMAN_GENERATOR_POSTMAN_TOKEN'),
            'api_key' => env('POSTMAN_GENERATOR_POSTMAN_API_KEY'),
        ],
        'environments' => [
            'local' => [
                'base_url' => env('POSTMAN_GENERATOR_ENV_LOCAL_BASE_URL'),
                'token' => env('POSTMAN_GENERATOR_ENV_LOCAL_TOKEN'),
                'api_key' => env('POSTMAN_GENERATOR_ENV_LOCAL_API_KEY'),
            ],
        ],
    ],
];

Environment Output

Environment files are generated alongside the collection:

storage/app/postman/environment.local.json

Filters

'scan' => [
    'include_tags' => ['Users'],
    'exclude_tags' => ['Internal'],
    'include_namespaces' => ['App\\Http\\Controllers\\Api'],
    'exclude_domains' => ['telescope'],
],

Testing

composer test
composer analyse
composer fix:dry

License

MIT

nutandc/laravel-postman-generator 适用场景与选型建议

nutandc/laravel-postman-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「generator」 「documentation」 「api」 「laravel」 「Postman」 「openapi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 nutandc/laravel-postman-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nutandc/laravel-postman-generator 我们能提供哪些服务?
定制开发 / 二次开发

基于 nutandc/laravel-postman-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

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