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)1649↓64.7%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 today

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 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

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

939d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1143595?v=4)[Matt Radford](/maintainers/MattyRad)[@MattyRad](https://github.com/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

3.0k37.6M134](/packages/darkaonline-l5-swagger)[nelmio/api-doc-bundle

Generates documentation for your REST API from attributes

2.4k67.4M263](/packages/nelmio-api-doc-bundle)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M572](/packages/shopware-core)[tangwei/apidocs

A swagger library for Hyperf.

53137.0k8](/packages/tangwei-apidocs)[hyperf/swagger

A swagger library for Hyperf.

20371.1k7](/packages/hyperf-swagger)[pimcore/studio-backend-bundle

Pimcore Studio Backend Bundle

20203.9k22](/packages/pimcore-studio-backend-bundle)

PHPackages © 2026

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