PHP code example of openapi-tools / representation
1. Go to this page and download the library: Download openapi-tools/representation 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 / representation example snippets
use OpenAPITools\Representation\Representation;
use OpenAPITools\Utils\Namespace_;
$representation = new Representation(
client: $client,
webHooks: $webHooks,
schemas: $schemas,
);
$namespaced = $representation->namespace(
new Namespace_('Vendor\\Api', 'Vendor\\Tests\\Api'),
);
use OpenAPITools\Representation\Contract;
use OpenAPITools\Representation\Property;
use OpenAPITools\Representation\Schema;
$schema = new Schema(
className: 'Schema\\User',
contracts: [
new Contract('Contract\\User', [$property]),
],
errorClassName: 'Schema\\Error\\User',
errorClassNameAliased: 'Schema\\ErrorAlias\\User',
title: 'User',
description: 'A user resource',
example: [],
properties: [$property],
schema: $openApiSchema,
isArray: false,
type: [],
alias: [],
);
$namespaced = $schema->namespace($namespace);
$namespaced->className->fullyQualified->source; // \Vendor\Api\Schema\User
$namespaced->errorClassName->fullyQualified->source; // \Vendor\Api\Schema\Error\User
$namespaced->contracts[0]->className->fullyQualified->source; // \Vendor\Api\Contract\User
use OpenAPITools\Representation\Hydrator;
use OpenAPITools\Representation\Path;
$path = new Path(
className: 'Path\\Users',
hydrator: new Hydrator(
className: 'Hydrators\\Users',
methodName: 'users',
schemas: [$schema],
),
operations: [$operation],
);
$namespaced = $path->namespace($namespace);
$namespaced->className->fullyQualified->source; // \Vendor\Api\Path\Users
$namespaced->hydrator->className->fullyQualified->source; // \Vendor\Api\Hydrators\Users
$namespaced->hydrator->schemas[0]->className->fullyQualified->source; // \Vendor\Api\Schema\User
use OpenAPITools\Representation\WebHook;
$webHook = new WebHook(
event: 'user.created',
summary: 'User created',
description: 'Sent when a user is created',
operationId: 'userCreated',
documentationUrl: 'https://example.com/docs/webhooks/user-created',
headers: [$header],
schema: ['application/json' => $schema],
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.