PHPackages                             alextech/expressive-route-openapi-doc - 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. alextech/expressive-route-openapi-doc

ActiveLibrary

alextech/expressive-route-openapi-doc
=====================================

Generate OpenAPI schema doc from expressive routes

0.9.1(7y ago)03PHPPHP ^7.1

Since Jan 3Pushed 7y ago1 watchersCompare

[ Source](https://github.com/alextech/expressive-route-openapi-doc)[ Packagist](https://packagist.org/packages/alextech/expressive-route-openapi-doc)[ RSS](/packages/alextech-expressive-route-openapi-doc/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

Expressive-Route-OpenAPI
========================

[](#expressive-route-openapi)

Generate OpenAPI doc skeleton from expressive routes.

`RouteOpenApiDoc` uses application's router configuration to generate OpenAPI skeleton. The skeleton includes placeholders to write description for paths and their parameters, and references to schemas for REST style resources that are inferred from path segments. Besides being displayed in viewers like [swagger-ui](https://swagger.io/tools/swagger-ui/), these schemas can be used for validating`requestBody` in your middleware pipeline.

Other API documentation libraries focus on parsing annotations. While docblock annotations may be useful for MVC-style frameworks, where routing table and Controller/Actions are in separate locations making the connection between the two difficult to keep track of without extra hints, middleware-style frameworks, especially the [PSR-15](https://www.php-fig.org/psr/psr-15/) compatible ones have the routing and handlers in one place, making extra docblocks for API documentation generators to parse redundant. Or, they try to generate code based on existing API specification, which behaves too CRUD-y, and may not be compatible with existing codebase.

Usage
-----

[](#usage)

In your router configuration function, get an instance of `OpenApiWriter` service. Add instance of `Application` or `RouteCollector` (if defining routes in multiple configurations using [path segregated piplines](https://docs.zendframework.com/zend-expressive/v3/cookbook/path-segregated-routing/), that has the routes needing to be documented, and call `writeSpec`.

```
use RouteApiDoc\RouterStrategy\RouterStrategyInterface;

return function (Application $app, MiddlewareFactory $factory, ContainerInterface $container) : void {
    // your API resources and handlers
    $app->get('/api/resources/:resource_id', []);
    $app->post('/api/resources', []);

    $apiWriter = $container->get(OpenApiWriter::class);
    $appWriter->addApplication($app);
    $apiWriter->writeSpec($app);
}
```

This will produce a json file `api_doc.json` in the output directory configured as described next.

If you made changes to the generated file, as you most likely will since this is just a skeleton, and rerun the writer, changes will be merged.

By default, each guessed resource will be written to its own json schema file. If prefer to have all schemas as part of one single document, pass `true` as a parameter of `writeSpec()`.

> Since the generation of documents is a development task, and will slow down requests, it is recommended to have the above lines conditional only for development mode.

#### Base path

[](#base-path)

If you are adding multiple route containers using `$apiWriter->addRouteCollector()` or `$apiWriter->addApplication()`, chances are you are using *path segregated pipelines* technique to organize your routes. In this case, you will need to let the api writer know about the pipeline basepath because is not exposed by expressive to the route collection. Specify it as a second parameter of the `add` functions. Base path will also become a tag for all the routes starting from that path.

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

[](#configuration)

Configuration is read from `openapi_writer` key of your application config. It is expected to have these options:

```
[
    'router_strategy' => RouteApiDoc\RouterStrategy\ZendRouterStrategy::class
    'output_directory' => __DIR__ . '/spec'
]

```

- `router_strategy` - name of strategy that knows how to interpret the syntax of your chosen route matching library. (So far only Zend Router is supported. FastRoute will be coming next)
- `output_directory` - directory path where schema files will be written

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 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

Every ~0 days

Total

2

Last Release

2682d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a3a165f7228fed4b5edcd0d19ff3cbf403d4916da92134cbcb646187b50a9975?d=identicon)[alextech](/maintainers/alextech)

---

Top Contributors

[![alextech](https://avatars.githubusercontent.com/u/3820828?v=4)](https://github.com/alextech "alextech (44 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alextech-expressive-route-openapi-doc/health.svg)

```
[![Health](https://phpackages.com/badges/alextech-expressive-route-openapi-doc/health.svg)](https://phpackages.com/packages/alextech-expressive-route-openapi-doc)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k509.9M16.9k](/packages/laravel-framework)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k48.1M234](/packages/api-platform-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[tempest/framework

The PHP framework that gets out of your way.

2.1k23.1k9](/packages/tempest-framework)[api-platform/metadata

API Resource-oriented metadata attributes and factories

223.5M96](/packages/api-platform-metadata)

PHPackages © 2026

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