PHPackages                             mattyrad/openapi-serialize - 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. mattyrad/openapi-serialize

ActiveLibrary[API Development](/categories/api)

mattyrad/openapi-serialize
==========================

Serialize an object directly from Swagger-PHP attributes

1.0.0(2y ago)1577↓25%MITPHPPHP ^8.1

Since Dec 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/MattyRad/openapi-serialize)[ Packagist](https://packagist.org/packages/mattyrad/openapi-serialize)[ RSS](/packages/mattyrad-openapi-serialize/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

openapi-serialize
=================

[](#openapi-serialize)

Serialize an object directly from [swagger-php](https://github.com/zircote/swagger-php) attributes.

```
composer require mattyrad/openapi-serialize
```

```
use OpenApi\Attributes as OpenApi;

$sample = new class() {
    public function __construct(
        #[OpenApi\Property]
        public readonly int $two_plus_two = 4,
    ) {}

    #[OpenApi\Property(property: 'greeting')]
    public function getGreeting(): string
    {
        return 'hello world';
    }
};

$serialized = MattyRad\OpenApi\Serializer::serialize($sample);

assert($serialized == ['two_plus_two' => 4, 'greeting' => 'hello world']);
```

This means that if you document all of your response data using swagger-php attributes, your API documentation will *necessarily* match the response format.

The need for tests to verify that a response matches OpenApi schema mostly becomes a formality- or altogether unnecessary.

Examples
--------

[](#examples)

```
use MattyRad\OpenApi\Serializer;
use OpenApi\Attributes as OpenApi;

abstract class HttpResource implements \JsonSerializable
{
    final public function jsonSerialize(): array|string
    {
        return Serializer::serialize($this);
    }
}

final class Greeting extends HttpResource
{
    public function __construct(
        #[OpenApi\Property]
        public readonly string $hello = 'world',
    ) {}
}

// return new JsonResponse(new Greeting)
```

Or a trait if you don't want to lock in to abstractions.

```
use MattyRad\OpenApi;

trait SerializesFromOpenApi
{
    final public function jsonSerialize(): array|string
    {
        return Serializer::serialize($this);
    }
}

final class Greeting implements \JsonSerializable
{
    use SerializesFromOpenApi;

    public function __construct(
        #[OpenApi\Property]
        public readonly string $hello = 'world',
    ) {}
}

// return new JsonResponse(new Greeting)
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

Unknown

Total

1

Last Release

893d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/754b009b104113d3b00daab6452c25805a12a335e2484d1dde41e0d2933672b7?d=identicon)[MattyRad](/maintainers/MattyRad)

---

Top Contributors

[![MattyRad](https://avatars.githubusercontent.com/u/1143595?v=4)](https://github.com/MattyRad "MattyRad (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mattyrad-openapi-serialize/health.svg)

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

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k34.0M112](/packages/darkaonline-l5-swagger)[darkaonline/swagger-lume

OpenApi or Swagger integration to Lumen

3372.3M3](/packages/darkaonline-swagger-lume)[jlapp/swaggervel

A great way to integrate Swagger into Laravel

492931.6k2](/packages/jlapp-swaggervel)[light/yii2-swagger

swagger intergation with yii2

154801.6k4](/packages/light-yii2-swagger)[yii2mod/yii2-swagger

Swagger Documentation Generator for Yii2 Framework

63384.7k9](/packages/yii2mod-yii2-swagger)[alt3/cakephp-swagger

Instant Swagger documentation for your CakePHP 4.x APIs

64197.3k3](/packages/alt3-cakephp-swagger)

PHPackages © 2026

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