dunglas / php-to-json-schema
Generate a JSON schema from a PHP entity
Installs: 2 018
Dependents: 0
Suggesters: 0
Security: 0
Stars: 30
Watchers: 1
Forks: 3
Open Issues: 2
Requires
- php: >=7.0
- symfony/property-info: ~2.8|~3.0
Requires (Dev)
- phpdocumentor/reflection: ^1.0.7
This package is auto-updated.
Last update: 2022-01-10 20:44:46 UTC
README
This library is deprecated, use API Platform JSON Schema instead.
Creates a JSON Schema from a PHP entity. Useful to ensure that a given JSON document will be deserialized properly in an object graph.
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.