PHPackages                             giann/schematics - 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. giann/schematics

ActiveLibrary[API Development](/categories/api)

giann/schematics
================

Models that can be translated to JSON Schemas

3.5(2mo ago)6102MITPHPPHP ^8.1CI passing

Since Jun 24Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/giann/schematics)[ Packagist](https://packagist.org/packages/giann/schematics)[ RSS](/packages/giann-schematics/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (8)Versions (55)Used By (0)

schematics
==========

[](#schematics)

Translates PHP classes to JSON Schema and back.

Supported Drafts
----------------

[](#supported-drafts)

Only commonly used drafts `draft-04` and `2020-12` are supported.

Example
-------

[](#example)

```
enum Sex: string
{
    case Male = 'male';
    case Female = 'female';
    case Other = 'other';
}

#[ObjectSchema]
class Person
{
    public function __construct(
        #[StringSchema(format: Format::Uuid)]
        #[Description('unique id of the person')]
        public string $id,

        #[ArraySchema(
            items: new StringSchema(),
            minContains: 1
        )]
        public array $names,

        #[IntegerSchema(minimum: 0)]
        public int $age,

        #[StringSchema(enumClass: Sex::class)]
        public string $sex,

        // Inferred $ref to self
        public ?Person $father = null
    ) {
	}
}

enum Power: string
{
    case Fly = 'weeeee!';
    case Strong = 'smash!';
    case Psychic = 'hummmm!';
}

// Infer $allOf Person
#[ObjectSchema]
class Hero extends Person
{
    public function __construct(
        string $id,
        array $names,
        int $age,
        string $sex,
        ?Person $father = null,

        // Infers string property
        public string $superName,

        #[StringSchema(enumClass: Power::class)]
        public string $power
    ) {
        parent::__construct($id, $names, $age, $sex, $father);
    }
}
```

Results in the following JSON Schema:

```
{
  "type": "object",
  "$defs": {
    "Person": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "unique id of the person",
          "format": "uuid"
        },
        "names": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minContains": 1
        },
        "age": {
          "type": "integer",
          "minimum": 0
        },
        "sex": {
          "type": "string",
          "enum": ["male", "female", "other"]
        },
        "father": {
          "oneOf": [
            {
              "type": "null"
            },
            {
              "$ref": "#/$defs/Person"
            }
          ]
        }
      },
      "required": ["id", "names", "age", "sex", "father"]
    }
  },
  "allOf": [
    {
      "$ref": "#/$defs/Person"
    }
  ],
  "properties": {
    "superName": {
      "type": "string"
    },
    "power": {
      "type": "string",
      "enum": ["weeeee!", "smash!", "hummmm!"]
    }
  },
  "required": ["superName", "power"]
}
```

Not Yet Supported
-----------------

[](#not-yet-supported)

- `$dynamicRef`
- `$dynamicAnchor`

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance84

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity63

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

Recently: every ~141 days

Total

54

Last Release

81d ago

Major Versions

1.7.3 → 2.0.02024-07-15

2.4.0 → 3.0.02024-07-24

PHP version history (2 changes)1.0.0PHP ^8.0

3.3.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/584398?v=4)[Benoit Giannangeli](/maintainers/giann)[@giann](https://github.com/giann)

---

Top Contributors

[![giann](https://avatars.githubusercontent.com/u/584398?v=4)](https://github.com/giann "giann (116 commits)")

---

Tags

apijsonjson-schemaphpphp74php81

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/giann-schematics/health.svg)

```
[![Health](https://phpackages.com/badges/giann-schematics/health.svg)](https://phpackages.com/packages/giann-schematics)
```

###  Alternatives

[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M99](/packages/dedoc-scramble)[knuckleswtf/scribe

Generate API documentation for humans from your Laravel codebase.✍

2.3k14.2M62](/packages/knuckleswtf-scribe)[phpdocumentor/phpdocumentor

Documentation Generator for PHP

4.4k3.1M906](/packages/phpdocumentor-phpdocumentor)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[cakephp/bake

Bake plugin for CakePHP

11212.0M201](/packages/cakephp-bake)

PHPackages © 2026

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