定制 lpmatrix/postman-generator 二次开发

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

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

lpmatrix/postman-generator

Composer 安装命令:

composer require lpmatrix/postman-generator

包简介

Laravel package that automatically generates a Postman collection from Laravel routes

README 文档

README

A Laravel package that automatically generates a Postman collection from your Laravel routes, including support for route groups, authentication settings, and customization options.

Features

  • Automatic generation of Postman Collection v2.1 from Laravel routes
  • Support for route grouping (by prefix, controller, or middleware)
  • Intelligent handling of route parameters and request bodies
  • Support for FormRequest validation rules to generate example requests
  • Authentication configuration (Bearer token, Basic auth)
  • Environment variables support
  • Customizable output with pretty-printing option
  • Works with Laravel 10.x and above

Installation

You can install the package via composer:

composer require lpmatrix/postman-generator

The service provider will be automatically registered for Laravel 8+.

Configuration

To publish the configuration file:

php artisan vendor:publish --provider="LPMatrix\PostmanGenerator\PostmanGeneratorServiceProvider" --tag="config"

This will create a config/postman-generator.php file where you can customize the behavior of the package.

Usage

Basic Usage

To generate a Postman collection:

php artisan postman:generate

This will create a postman-collection.json file in your project root that you can import into Postman.

Command Options

# Specify a custom output path
php artisan postman:generate --output=custom-file.json

# Pretty-print the JSON output
php artisan postman:generate --pretty

# Include environment variables
php artisan postman:generate --include-env

Configuration Options

Collection Settings

// The name of the generated Postman collection
'collection_name' => env('POSTMAN_COLLECTION_NAME', config('app.name') . ' API'),

// Description for the collection
'description' => env('POSTMAN_COLLECTION_DESCRIPTION', 'API Documentation'),

// Base URL for all requests (can use Postman variables)
'base_url' => '{{baseUrl}}',

// Default base URL value 
'default_base_url' => env('APP_URL', 'http://localhost') . '/api',

Route Filtering

// Only include API routes (those with uri starting with 'api/')
'api_routes_only' => true,

// Route URI patterns to exclude
'exclude_patterns' => [
    '_debugbar/*',
    'sanctum/*',
    // ...
],

// HTTP methods to exclude
'exclude_methods' => [
    'HEAD',
    'OPTIONS',
],

Route Grouping

// Strategy for grouping routes into folders
// Supported values: 'prefix', 'controller', 'middleware', 'custom'
'grouping_strategy' => 'prefix',

// Custom grouping function - only used when grouping_strategy is 'custom'
'custom_grouping' => function ($route) {
    // Your custom logic here
    return 'Your Group Name';
},

Authentication

// Authentication type for the collection
// Supported values: 'noauth', 'bearer', 'basic'
'auth' => [
    'type' => 'bearer',
    'token' => 'your-default-token',
],

Advanced Usage Examples

Custom Route Grouping

If you want to implement a custom grouping logic, you can define a closure in your AppServiceProvider:

use Acme\PostmanGenerator\PostmanGenerator;

public function boot()
{
    config(['postman-generator.grouping_strategy' => 'custom']);
    config(['postman-generator.custom_grouping' => function ($route) {
        // Your custom grouping logic
        $uri = $route->uri();
        $method = $route->methods()[0];
        
        // Group by HTTP method
        return strtoupper($method);
    }]);
}

Extracting Documentation from Route Annotations

This package automatically extracts documentation from PHPDoc comments in your controller methods. For best results, document your API endpoints like this:

/**
 * Get a list of all products.
 * 
 * This endpoint returns a paginated list of products with basic information.
 * 
 * @return \Illuminate\Http\Response
 */
public function index()
{
    // Your code here
}

Using with FormRequest Validation

The package automatically detects FormRequest validation rules to generate example request bodies:

public function store(StoreProductRequest $request)
{
    // When StoreProductRequest contains validation rules, they will be used
    // to generate an example request body with appropriate data types
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

The MIT License (MIT). Please see License File for more information.

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

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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