Skip to content
Creates a JSON Schema from a PHP class
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
.travis.yml
LICENSE
README.md Minor README fix Feb 14, 2018
composer.json
phpunit.xml.dist

README.md

PHP to JSON Schema

Creates a JSON Schema from a PHP entity. Useful to ensure that a given JSON document will be deserialized properly in an object graph.

Build Status Scrutinizer Code Quality SensioLabsInsight

Installation

Use https://getcomposer.org to install the library:

composer require dunglas/php-to-json-schema

Usage

use Dunglas\PhpToJsonSchema\Generator;
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;

class MyClass
{
    private $foo;
    private $bar;

    public function setFoo(string $foo)
    {
        $this->foo = $foo;
    }

    public function setBar(float $bar = null)
    {
        $this->bar = $bar;
    }

    // ...
}


$reflectionExtractor = new ReflectionExtractor();
$propertyInfoExtractor = new PropertyInfoExtractor([$reflectionExtractor], [$reflectionExtractor], [], [$reflectionExtractor]);

$generator = new Generator($propertyInfoExtractor);
echo json_encode($generator->generate(MyClass::class));

Credits

Created by Kévin Dunglas.

You can’t perform that action at this time.