wwwision/types-jsonschema
Generator for JSON Schema files from PHP classes, see https://json-schema.org/
Maintainers
2.1.0
2025-08-07 19:46 UTC
Requires
- php: >=8.1
- webmozart/assert: ^1
- wwwision/jsonschema: ^1
- wwwision/types: ^1.7
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3
- phpstan/phpstan: ^2
- phpunit/phpunit: ^10 || ^11 || ^12
- roave/security-advisories: dev-latest
Suggests
None
Provides
None
Conflicts
None
Replaces
None
MIT d8f9c35e2de0e605c364e5ddc953cd31f5fd4e5e
- bwaidelich <b.waidelich.woop@wwwision.de>
README
Integration for the wwwision/types package that allows to generate JSON Schema files from PHP code
Usage
This package can be installed via composer:
composer require wwwision/types-jsonschema
With that, you can create JSON Schema from PHP classes:
class Contact { public function __construct(public string $name, public int $age) {} } $schema = (new JsonSchemaGenerator())->fromClass(Contact::class); $expected = <<<JSON { "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "integer" } }, "additionalProperties": false, "required": [ "name", "age" ] } JSON; assert(json_encode($schema, JSON_PRETTY_PRINT) === $expected);
Advanced schemas
All attributes of the wwwision/types package are supported in order to create sophisticated schemas.
