PHPackages                             route2api/route2api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. route2api/route2api

ActiveLibrary[API Development](/categories/api)

route2api/route2api
===================

Generate OpenAPI and Markdown API documents from ThinkPHP routes and controllers.

v0.1.0(1mo ago)13MITPHPPHP &gt;=7.0

Since Jul 2Pushed 1mo agoCompare

[ Source](https://github.com/ruaibeite/route2api)[ Packagist](https://packagist.org/packages/route2api/route2api)[ RSS](/packages/route2api-route2api/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (2)Used By (0)

Route2API
=========

[](#route2api)

Route2API is an open-source API documentation generator for PHP projects. The first version focuses on ThinkPHP: it scans routes and controller comments, then exports OpenAPI, Postman Collection, Markdown, and HTML documents.

中文：Route2API 是一个面向 PHP 项目的接口文档自动生成工具。第一版重点支持 ThinkPHP，可以扫描路由和控制器注释，生成 OpenAPI、Postman Collection、Markdown、HTML 文档，方便导入 Apifox、ApiPost、Postman、Swagger UI、Redoc 等工具。

Features
--------

[](#features)

- Scan ThinkPHP `route/*.php`
- Detect `Route::get/post/put/delete/patch/any`
- Detect simple `Route::group`
- Expand `Route::resource`
- Read controller method PHPDoc
- Infer request parameters from common controller code patterns
- Infer required fields from simple validation rules and `requireFields(...)`
- Export OpenAPI 3.0 JSON
- Export OpenAPI 3.0 YAML
- Export Postman Collection v2.1 JSON
- Export Markdown
- Export static HTML
- Generate a starter `route2api.yaml`

Install
-------

[](#install)

Requirements:

- PHP 7.0 or later for Route2API itself
- ThinkPHP 6.x projects are supported for scanning
- ThinkPHP 6 runtime usually requires PHP 7.2.5 or later

Install Route2API as a development dependency in your ThinkPHP project:

```
composer require route2api/route2api --dev
```

Quick Start
-----------

[](#quick-start)

Run inside a ThinkPHP project:

```
vendor/bin/route2api scan --framework=thinkphp
```

Generate all supported formats:

```
vendor/bin/route2api scan \
  --framework=thinkphp \
  --output=docs/api \
  --format=openapi,yaml,postman,markdown,html
```

Generated files:

```
docs/api/openapi.json
docs/api/openapi.yaml
docs/api/postman_collection.json
docs/api/api.md
docs/api/index.html

```

Configuration
-------------

[](#configuration)

Create a starter config:

```
vendor/bin/route2api init
```

This creates `route2api.yaml`:

```
project:
  name: Demo API
  base_url: http://localhost

framework: thinkphp

scan:
  routes:
    - route/*.php
  controllers:
    - app/controller

output:
  dir: route2api
  formats:
    - openapi
    - yaml
    - postman
    - markdown
    - html
```

Then run:

```
vendor/bin/route2api scan
```

CLI options can override config values:

```
vendor/bin/route2api scan \
  --name="My API" \
  --base-url="https://api.example.com" \
  --output=docs/api
```

Supported ThinkPHP Route Syntax
-------------------------------

[](#supported-thinkphp-route-syntax)

```
use think\facade\Route;

Route::get('user/:id', 'User/read');
Route::post('user/login', 'User/login')->middleware('auth');

Route::group('api', function () {
    Route::get('profile', 'Profile/read');
});

Route::resource('articles', 'Article');
```

Controller Comments
-------------------

[](#controller-comments)

Route2API reads the PHPDoc above controller methods:

```
/**
 * 用户登录
 * 使用账号密码登录。
 *
 * @param string username 用户名
 * @param string password 密码
 */
public function login()
{
    // ...
}
```

`@param` is converted into request parameters in OpenAPI, Markdown, HTML, and Postman output.

Import Into API Tools
---------------------

[](#import-into-api-tools)

Apifox, ApiPost, Postman, Swagger UI, and Redoc can consume the generated output.

- Apifox: import `openapi.json`, `openapi.yaml`, or `postman_collection.json`
- ApiPost: import `openapi.json`, `openapi.yaml`, or `postman_collection.json`
- Postman: import `postman_collection.json` or `openapi.json`
- Swagger UI / Redoc: use `openapi.json` or `openapi.yaml`

Current Limitations
-------------------

[](#current-limitations)

Route2API v0.1 is intentionally small. It uses static analysis and does not execute project code.

- Complex nested route groups are not fully parsed yet
- Request body schemas are inferred from common patterns such as `$this->input()`, `$this->request->get(...)`, `requireFields(...)`, and simple validation arrays
- Complex dynamic parameters may still need manual cleanup after generation
- Full validator and model field scanning are planned
- Laravel support is planned
- Manual endpoint overrides are planned

The recommended workflow is: scan code first, then use the generated OpenAPI or Markdown as the draft API document.

Roadmap
-------

[](#roadmap)

- ThinkPHP validator rule extraction
- Request body schema generation
- Manual endpoint override file
- Laravel route and FormRequest scanner
- HTML theme improvements
- CI command for regenerating docs
- Optional web UI

Contributing
------------

[](#contributing)

Clone the repository and run the smoke test:

```
tests/smoke.sh
```

Run syntax checks:

```
find . -name '*.php' -exec php -l {} \;
```

License
-------

[](#license)

MIT

###  Health Score

31

—

LowBetter than 65% of packages

Maintenance90

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

48d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8d93290854894e4255da36473f5f32822b7180e04c452818eb2e74d5fa5088ee?d=identicon)[ruaibeite](/maintainers/ruaibeite)

---

Top Contributors

[![ruaibeite](https://avatars.githubusercontent.com/u/45942830?v=4)](https://github.com/ruaibeite "ruaibeite (5 commits)")

---

Tags

openapimarkdownPostmanthinkphpapi-documentation

### Embed Badge

![Health badge](/badges/route2api-route2api/health.svg)

```
[![Health](https://phpackages.com/badges/route2api-route2api/health.svg)](https://phpackages.com/packages/route2api-route2api)
```

###  Alternatives

[swagger-api/swagger-ui

 Swagger UI is a collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.

29.0k51.0M117](/packages/swagger-api-swagger-ui)[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k38.9M150](/packages/darkaonline-l5-swagger)[hg/apidoc-thinkphp

thinkphp API文档自动生成

1291.9k](/packages/hg-apidoc-thinkphp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
