PHPackages                             avalanche-development/swagger-router-middleware - 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. avalanche-development/swagger-router-middleware

ActiveLibrary[API Development](/categories/api)

avalanche-development/swagger-router-middleware
===============================================

1.2.2(9y ago)11.9k1[1 PRs](https://github.com/avalanche-development/swagger-router-middleware/pulls)3MITPHPPHP &gt;=5.6.0

Since Oct 13Pushed 8y ago1 watchersCompare

[ Source](https://github.com/avalanche-development/swagger-router-middleware)[ Packagist](https://packagist.org/packages/avalanche-development/swagger-router-middleware)[ RSS](/packages/avalanche-development-swagger-router-middleware/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (5)Versions (31)Used By (3)

swagger-router-middleware
=========================

[](#swagger-router-middleware)

PHP middleware that parses and attaches [swagger](http://swagger.io/) information to a request object.

[![Build Status](https://camo.githubusercontent.com/fe59ae8cf2135875a605650b19a897650b9046bff8a5256a2be72dd3725e60c3/68747470733a2f2f7472617669732d63692e6f72672f6176616c616e6368652d646576656c6f706d656e742f737761676765722d726f757465722d6d6964646c65776172652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/avalanche-development/swagger-router-middleware)[![Code Climate](https://camo.githubusercontent.com/0ec4e2248d124e60ace4cc2d91e9b489a2fb70647a6c3b9bdfb0d08509d42874/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6176616c616e6368652d646576656c6f706d656e742f737761676765722d726f757465722d6d6964646c65776172652f6261646765732f6770612e737667)](https://codeclimate.com/github/avalanche-development/swagger-router-middleware)[![Test Coverage](https://camo.githubusercontent.com/f1fb9e513a68d11060dfede1a3de26b2d838baa29befaa6bb44146ce505a980b/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6176616c616e6368652d646576656c6f706d656e742f737761676765722d726f757465722d6d6964646c65776172652f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/avalanche-development/swagger-router-middleware/coverage)

Installation
------------

[](#installation)

It's recommended that you use [Composer](https://getcomposer.org/) to install swagger-router-middleware.

```
$ composer require avalanche-development/swagger-router-middleware
```

swagger-router-middleware requires PHP 5.6 or newer.

Usage
-----

[](#usage)

This middleware is instantiated with swagger (in the form of an array) and then, when invoked as middleware, will walk through the swagger document and parse things out. Specifically, it will pull out the path and operation, resolve parameters and security definitions, and parse out parameters based on the swagger definition.

```
$router = new AvalancheDevelopment\SwaggerRouterMiddleware\Router([..swagger..]);
$result = $router($request, $response, $next); // middleware signature
```

It is recommended that this is one of the top items in the stack, as the swagger information that is parsed out can be used for request/response validation deeper in.

### Interface

[](#interface)

Once everything passes through successfully, the $request object will have the following attribute passed on.

```
'swagger' => [
    'apiPath' => '/comments/{comment_id}', // matched string path
    'path' => [ ... ], // full path definition
    'operation' => [ ... ], // specific operation definition
    'params' => [ ... ], // resolved list of parameters for this operation
    'security' => [ ... ], // resolved list of securities
    'schemes' => [ ... ], // resolved list of schemes
    'produces' => [ ... ], // resolved list of producible content types
    'consumes' => [ ... ], // resolved list of consumable content types
    'responses' => [ ... ], // resolved list of responses
]
```

An important note is that each parameter in the list will include a 'value' key that, if the parameter was passed into the request (or has a default), will be populated.

### Documentation Route

[](#documentation-route)

If the standard 'documentation route' is detected (path of /api-docs), the rest of the stack is immediately skipped and the swagger spec is returned as json. An error with json\_encode will throw a standard \\Exception.

### Invalid Requests

[](#invalid-requests)

There is some routing being done here. If the request route cannot be found in swagger, or if the method is not supported, appropriate [peel](https://github.com/avalanche-development/peel) exceptions are thrown. Also, if there is an error with parameter parsing that appears to be an issue with request, a peel BadRequest is thrown. An error handler can listen for these HttpErrorInterface exceptions and respond appropriately.

### Parameter Parsing

[](#parameter-parsing)

The middleware will do it's best to parse out the parameters for the request without too much validation. It loops through the swagger definition, looking for the parameters that are applicable for the route, and pull them from header/query/path/etc.

Again, this middleware will not check the existence, validity, or type of parameters based on the spec. It only tries to pull and expects something else in the stack to verify integrity.

Development
-----------

[](#development)

This library is still being developed and some bugs may be experienced. Feel free to add issues or submit pull requests when road bumps are noticed.

### Tests

[](#tests)

To execute the test suite, you'll need phpunit (and to install package with dev dependencies).

```
$ phpunit
```

License
-------

[](#license)

swagger-router-middleware is licensed under the MIT license. See [License File](LICENSE) for more information.

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity69

Established project with proven stability

 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 ~8 days

Recently: every ~16 days

Total

28

Last Release

3316d ago

Major Versions

0.11.0 → 1.0.02017-01-20

### Community

Maintainers

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

---

Top Contributors

[![jacobemerick](https://avatars.githubusercontent.com/u/527814?v=4)](https://github.com/jacobemerick "jacobemerick (167 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/avalanche-development-swagger-router-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/avalanche-development-swagger-router-middleware/health.svg)](https://phpackages.com/packages/avalanche-development-swagger-router-middleware)
```

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69735.1M148](/packages/algolia-algoliasearch-client-php)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M719](/packages/sylius-sylius)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.7k371.6k6](/packages/theodo-group-llphant)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35729.6k2](/packages/telnyx-telnyx-php)

PHPackages © 2026

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