luca-rath/php-json-schema

PHP classes to help create json schemas

dev-main 2020-12-12 15:53 UTC

This package is auto-updated.

Last update: 2024-04-29 04:34:07 UTC


README

License Latest tag GitHub Actions Scrutinizer build Scrutinizer coverage Scrutinizer code quality

PHP classes to help create json schemas

Installation

composer require luca-rath/php-json-schema

Usage

use JsonSchema\Keyword\FormatKeyword;
use JsonSchema\Property\Property;
use JsonSchema\Schema\IntegerSchema;
use JsonSchema\Schema\ObjectSchema;
use JsonSchema\Schema\StringSchema;

ObjectSchema::create()
    ->title('Registration form')
    ->properties([
        Property::create('email', true, StringSchema::create()
            ->format(FormatKeyword::FORMAT_EMAIL)
            ->examples(['admin@example.org'])),
        Property::create('password', true, StringSchema::create()
            ->minLength(8)
            ->description('The password must be at least eight characters long')),
        Property::create('age', false, IntegerSchema::create()
            ->nullable()
            ->minimum(18)),
    ]);