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.4(1mo ago)6101MITPHPPHP ^8.1CI passing

Since Jun 24Pushed 1mo ago3 watchersCompare

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

READMEChangelogDependencies (4)Versions (54)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

46

—

FairBetter than 93% of packages

Maintenance89

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

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

Total

53

Last Release

57d 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://www.gravatar.com/avatar/cc0d14e0bc6781ac17da02ac1d34ad9eee514686a592a6e7cc13efe15ed72e59?d=identicon)[giann](/maintainers/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

[knuckleswtf/scribe

Generate API documentation for humans from your Laravel codebase.✍

2.3k12.2M45](/packages/knuckleswtf-scribe)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.0k7.8M57](/packages/dedoc-scramble)[phpdocumentor/phpdocumentor

Documentation Generator for PHP

4.4k3.1M878](/packages/phpdocumentor-phpdocumentor)[jane-php/jane-php

All jane libraries into one repository

678254.7k4](/packages/jane-php-jane-php)[code-lts/doctum

Doctum, a PHP API documentation generator. Fork of Sami

35077.9k31](/packages/code-lts-doctum)[jane-php/open-api-3

Generate a PHP Client API (PSR7/PSR18 compatible) given a OpenApi 3.x specification

201.4M87](/packages/jane-php-open-api-3)

PHPackages © 2026

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