PHP code example of pandaleague / jsonschemabuilder
1. Go to this page and download the library: Download pandaleague/jsonschemabuilder library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pandaleague / jsonschemabuilder example snippets
use PandaLeague\JsonSchemaBuilder\Factory;
$schema = Factory::obj()
->title('User')
->description('A registered user')
->property('id', Factory::num()->minimum(1))
->property('email', Factory::str()->format('email'))
->property('roles', Factory::arr()
->items(Factory::str()->enum(['admin', 'user']))
->uniqueItems(true)
)
->
Factory::str()
->size(3, 32) // minLength / maxLength
->pattern('^[a-z]+$')
->format('email')
->default('admin');
Factory::num()
->minimum(0.5, exclusive: true)
->maximum(10.0)
->multipleOf(0.5)
->default(1.0);
Factory::arr()
->items(Factory::str()) // single schema, or
->items([Factory::str(), Factory::num()], additionalItems: false) // tuple
->size(1, 5) // minItems / maxItems
->uniqueItems(true);
Factory::obj()
->property('name', Factory::str())
->property('age', Factory::num())
->// minProperties / maxProperties
->propertyDependency('name', ['age'])
->patternProperty('^x-', Factory::str())
->propertyNames(Factory::str()->pattern('^[a-z]+$'));
Factory::bool()->default(true);
Factory::null();
Factory::str()->anyOf([
Factory::str()->format('email'),
Factory::str()->pattern('^\+?[0-9]+$'),
]);