luca-rath/php-json-schema

PHP类,帮助创建JSON模式

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

This package is auto-updated.

Last update: 2024-09-29 06:02:50 UTC


README

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

PHP类,帮助创建JSON模式

安装

composer require luca-rath/php-json-schema

用法

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)),
    ]);