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

ActiveLibrary

avalanche-development/swagger-header-middleware
===============================================

0.3.0(9y ago)04691MITPHPPHP &gt;=5.6.0

Since Nov 25Pushed 9y ago1 watchersCompare

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

READMEChangelogDependencies (5)Versions (6)Used By (1)

swagger-header-middleware
=========================

[](#swagger-header-middleware)

PHP middleware that tries to infer outbound content types and attach appropriate headers.

[![Build Status](https://camo.githubusercontent.com/0de7c17353a46453c9816258956c73f7085ef1cb34338c25fa939a8f8a443628/68747470733a2f2f7472617669732d63692e6f72672f6176616c616e6368652d646576656c6f706d656e742f737761676765722d6865616465722d6d6964646c65776172652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/avalanche-development/swagger-header-middleware)[![Code Climate](https://camo.githubusercontent.com/8d2bff17fd7217d78291f98261746135e713bc2ce83c7dc7704d65bf9a82f461/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6176616c616e6368652d646576656c6f706d656e742f737761676765722d6865616465722d6d6964646c65776172652f6261646765732f6770612e737667)](https://codeclimate.com/github/avalanche-development/swagger-header-middleware)[![Test Coverage](https://camo.githubusercontent.com/47d21bcc417a5efec3365611afa2c2d3a8212987ada27b46d83180767e6f49c2/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6176616c616e6368652d646576656c6f706d656e742f737761676765722d6865616465722d6d6964646c65776172652f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/avalanche-development/swagger-header-middleware/coverage)

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

[](#installation)

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

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

swagger-header-middleware requires PHP 5.6 or newer.

Usage
-----

[](#usage)

This middleware depends on [swagger-router-middleware](https://github.com/avalanche-development/swagger-router-middleware) to have a resolved swagger attribute attached to the request object. If it is not found, then all modifications to the response object are skipped. If it is, it will attempt to attach outbound content types.

```
$header = new AvalancheDevelopment\SwaggerHeaderMiddleware\Header;
$result = $header($request, $response, $next); // middleware signature
```

It is recommended that this is one of the top items in the stack, soon after swagger-router-middleware, and ensure that any sort of header validation is done after this is executed.

### Interface

[](#interface)

This middleware implements LoggerAwareInterface, so feel free to attach your logger for all that logging goodness.

```
$header = new AvalancheDevelopment\SwaggerHeaderMiddleware\Header;
$header->setLogger($logger);
... etc
```

Again, it depends on a swagger attribute being in the request. If a request object is passed in without it, then everything is skipped. Values are resolved based on the operation and global settings within the spec.

```
$swagger = $request->getAttribute('swagger');
var_dump($swagger);
...
[
  'produces' => [
    'application/json',
  ],
  'consumes' => [
    'application/json',
  ],
]
```

If a json string is passed in, then this middleware will automatically attach a `application/json` content-type header... only if a header is not already provided. To override this overreaching behavior, simply attach your own header before this is hit.

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

[](#development)

This library is in active development. Some things are not yet supported (such as detecting non-json header types).

### Tests

[](#tests)

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

```
$ phpunit
```

License
-------

[](#license)

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

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

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

Total

5

Last Release

3408d ago

### 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 (23 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mpdf/mpdf

PHP library generating PDF files from UTF-8 encoded HTML

4.7k77.1M490](/packages/mpdf-mpdf)[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[sylius/sylius

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

8.4k5.6M648](/packages/sylius-sylius)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69333.0M114](/packages/algolia-algoliasearch-client-php)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[theodo-group/llphant

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

1.5k311.5k5](/packages/theodo-group-llphant)

PHPackages © 2026

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