oooiik/laravel-export-postman 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

oooiik/laravel-export-postman

Composer 安装命令:

composer require oooiik/laravel-export-postman

包简介

Automatically generate a Postman collection based on your API routes.

README 文档

README

Latest Version on Packagist Total Downloads PHP Version License

Generate a Postman Collection v2.1 from your Laravel API routes — with a single Artisan command.

Annotate your controllers with simple PHPDoc tags to control authentication, headers, descriptions, and even Postman pre-request and test scripts. The output is a ready-to-import JSON collection — no manual route copying, no drift between code and docs.

Features

  • 🚀 One-command exportphp artisan postman:export and you're done
  • 🔐 Auth support — Bearer tokens, no-auth, parent-inherited, per-endpoint
  • 📝 Rich annotations — descriptions, headers, scripts via standard PHPDoc
  • 📂 External file sources — load descriptions and scripts from base_path() or resource_path()
  • Pre-request & test scripts — inject Postman JavaScript directly from your code
  • 🎯 Folder grouping — collections organized by route prefix
  • 🧩 Laravel 6 → 12 — broad compatibility, PHP 7.1+ through 8.x

Requirements

  • PHP 7.1 or higher
  • Laravel 6.x — 12.x

Installation

composer require oooiik/laravel-export-postman

Publish the config (optional):

php artisan vendor:publish --provider="Oooiik\LaravelExportPostman\ExportPostmanServiceProvider"

Quick Start

Export your routes to a Postman collection:

php artisan postman:export

The collection file will be created in your configured storage path. Import it into Postman → File → Import.

Configuration

Edit config/export-postman.php after publishing:

return [
    'name'        => env('APP_NAME', 'Laravel API'),
    'output_path' => storage_path('app/postman'),
    'base_url'    => env('APP_URL', 'http://localhost'),
    // ... and more
];

Annotation Reference

Add PHPDoc annotations to your controller methods or closures to enrich the generated collection.

Authentication

Annotation Description
@AuthNo No authentication for this endpoint
@AuthParent Inherit authentication from the parent folder
@AuthBearer [token] Use a Bearer token (literal value or Postman variable)
/**
 * @AuthBearer {{access_token}}
 */
public function show($id) { /* ... */ }

Headers

Use @Header key => value for custom request headers. Multiple @Header annotations are supported.

/**
 * @Header Accept => application/json
 * @Header X-Tenant-Id => {{tenant_id}}
 */
public function index() { /* ... */ }

Descriptions

Three flavors — inline, file from base_path(), file from resource_path(). They can be combined.

Annotation Source
@DescriptionContext [text] Inline markdown text
@DescriptionBasePath [path] File path relative to base_path()
@DescriptionResourcePath [path] File path relative to resource_path()
/**
 * @DescriptionContext Returns a paginated list of orders for the authenticated user.
 * @DescriptionResourcePath docs/api/orders-index.md
 */
public function index() { /* ... */ }

Pre-request Scripts

Inject Postman JavaScript that runs before the request is sent. Useful for token refresh, signature generation, or dynamic variables.

Annotation Source
@PreRequestScriptContext [js] Inline JavaScript
@PreRequestScriptFileBasePath [path] JS file relative to base_path()
@PreRequestScriptFileResourcePath [path] JS file relative to resource_path()
/**
 * @PreRequestScriptFileResourcePath postman/scripts/refresh-token.js
 */
public function transfer() { /* ... */ }

Test Scripts

Inject Postman JavaScript that runs after the response is received. Use for assertions or extracting values into environment variables.

Annotation Source
@TestScriptContext [js] Inline JavaScript
@TestScriptFileBasePath [path] JS file relative to base_path()
@TestScriptFileResourcePath [path] JS file relative to resource_path()
/**
 * @TestScriptContext pm.test("Status 200", () => pm.response.to.have.status(200));
 */
public function login() { /* ... */ }

Full Example

/**
 * @AuthBearer {{access_token}}
 * @Header Accept => application/json
 * @Header X-Tenant-Id => {{tenant_id}}
 * @DescriptionContext Creates a new order for the authenticated user.
 * @DescriptionResourcePath docs/api/orders-create.md
 * @PreRequestScriptFileResourcePath postman/scripts/sign-request.js
 * @TestScriptContext pm.test("Created", () => pm.response.to.have.status(201));
 */
public function store(StoreOrderRequest $request)
{
    // ...
}

Compatibility Matrix

Laravel PHP Status
12.x 8.2+ ✅ Supported
11.x 8.2+ ✅ Supported
10.x 8.1+ ✅ Supported
9.x 8.0+ ✅ Supported
8.x 7.3+ ✅ Supported
7.x 7.2.5+ ✅ Supported
6.x 7.2+ ✅ Supported

Contributing

Pull requests are welcome. For larger changes, please open an issue first to discuss the direction.

Feature ideas, bug reports, and questions → GitHub Issues.

Credits

License

The MIT License (MIT). See LICENSE for details.

oooiik/laravel-export-postman 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-12