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

ActiveLibrary

avalanche-development/swagger-caster-middleware
===============================================

0.2.1(8y ago)03321MITPHP

Since Apr 7Pushed 8y ago1 watchersCompare

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

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

swagger-caster-middleware
=========================

[](#swagger-caster-middleware)

PHP middleware that casts parameters into their respective types based on their [swagger](http://swagger.io/) definition. Information is stored in a AvalancheDevelopment\\ParsedSwaggerInterface attached to a Request object.

[![Build Status](https://camo.githubusercontent.com/179ef2f7ef3bf6b728cf112d1a09aa69c22c32d2afd9b830eb914a157030fc5e/68747470733a2f2f7472617669732d63692e6f72672f6176616c616e6368652d646576656c6f706d656e742f737761676765722d6361737465722d6d6964646c65776172652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/avalanche-development/swagger-caster-middleware)[![Code Climate](https://camo.githubusercontent.com/4b58e58bd69378d2ef63c274cc15164c397ad29cf1abee64216b434af66c0a57/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6176616c616e6368652d646576656c6f706d656e742f737761676765722d6361737465722d6d6964646c65776172652f6261646765732f6770612e737667)](https://codeclimate.com/github/avalanche-development/swagger-caster-middleware)[![Test Coverage](https://camo.githubusercontent.com/817bcfdbd798068c4c21026cdfa4ee9ac8164e867fe79e014f7b5399227bbfe7/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6176616c616e6368652d646576656c6f706d656e742f737761676765722d6361737465722d6d6964646c65776172652f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/avalanche-development/swagger-caster-middleware/coverage)

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

[](#installation)

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

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

swagger-caster-middleware requires PHP 5.6 or newer.

Usage
-----

[](#usage)

This middleware expects a AvalancheDevelopment\\ParsedSwaggerInterface attribute already filled out and attached to the Request object. Without it, all of logic will be skipped. Otherwise, the middleware will walk through the params array and cast each value, overwriting the original 'value' attribute with the casted one.

```
$caster = new AvalancheDevelopment\SwaggerCasterMiddleware\Caster();
$result = $caster($request, $response, $next); // middleware signature
```

It is recommended that this middleware occurs after AvalancheDevelopment\\SwaggerRouterMiddleware, which will parse out and attach the AvalancheDevelopment\\ParsedSwaggerInterface. Without it you'll need to reinvent the swagger/request parser.

### Interface

[](#interface)

Once everything passes through successfully, each param in the AvalancheDevelopment\\ParsedSwaggerInterface will have the following attributes.

```
'swagger' => [
    ...,
    'params' => [
        'originalValue' => 'true',
        'type' => 'boolean',
        'value' => true,
    ],
]
```

### Invalid Requests

[](#invalid-requests)

If there is an error with parameter casting 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. This is most relevant with date and date-time properties.

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-caster-middleware is licensed under the MIT license. See [License File](LICENSE) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

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

Total

5

Last Release

3267d 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 (36 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[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.6M651](/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)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[neos/flow

Flow Application Framework

862.0M451](/packages/neos-flow)

PHPackages © 2026

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