1. Go to this page and download the library: Download openapi-tools/registry 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/ */
openapi-tools / registry example snippets
use cebe\openapi\spec\Schema as OpenApiSchema;
use OpenAPITools\Registry\Schema;
$registry = new Schema(
allowDuplicatedSchemas: false,
useAliasesForDuplication: false,
);
$userSchema = new OpenApiSchema(['type' => 'object', 'title' => 'User']);
$registry->addClassName('User', $userSchema);
// Same JSON structure resolves to the pre-registered name.
$matching = new OpenApiSchema(['type' => 'object', 'title' => 'User']);
$registry->get($matching, 'Fallback'); // 'User'
// A new schema gets a class name from the fallback and is queued as unknown.
$other = new OpenApiSchema(['type' => 'string', 'format' => 'uuid']);
$registry->get($other, 'Uuid'); // 'Uuid'
while ($registry->hasUnknownSchemas()) {
foreach ($registry->unknownSchemas() as $unknown) {
// $unknown->name, $unknown->className, $unknown->schema
}
}
use cebe\openapi\spec\Schema as OpenApiSchema;
use OpenAPITools\Registry\Contract;
$contract = new Contract();
$inline = new OpenApiSchema([
'type' => 'object',
'properties' => ['id' => ['type' => 'integer']],
]);
$contract->get($inline, 'Contract\\User\\Profile'); // 'Contract\\User\\Profile'
foreach ($contract->contracts() as $registered) {
// $registered->name, $registered->className, $registered->schema
}
use OpenAPITools\Registry\ThrowableSchema;
$throwables = new ThrowableSchema();
$throwables->add('Schema\\NotFound');
$throwables->has('Schema\\NotFound'); // true
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.