PHP code example of openapi-tools / gatherer

1. Go to this page and download the library: Download openapi-tools/gatherer 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 / gatherer example snippets


use cebe\openapi\Reader;
use OpenAPITools\Configuration\Gathering;
use OpenAPITools\Configuration\Gathering\Schemas;
use OpenAPITools\Gatherer\Gatherer;

$representation = Gatherer::gather(
    Reader::readFromYamlFile('openapi.yaml'),
    new Gathering(
        spec: 'openapi.yaml',
        voter: null,
        schemas: new Schemas(
            allowDuplication: true,
            useAliasesForDuplication: true,
        ),
    ),
);

use OpenAPITools\Gatherer\Schema;
use OpenAPITools\Registry\Contract;
use OpenAPITools\Registry\Schema as SchemaRegistry;

$schemaRegistry   = new SchemaRegistry(allowDuplication: false, useAliasesForDuplication: false);
$contractRegistry = new Contract();

$schema = Schema::gather(
    'User',
    $openApiSchema,
    $schemaRegistry,
    $contractRegistry,
);

use OpenAPITools\Gatherer\ExampleData;
use OpenAPITools\Representation\Property\Type;

$example = ExampleData::gather(
    exampleData: null,
    type: new Type(
        type: 'scalar',
        format: 'uuid',
        pattern: null,
        payload: 'string',
        nullable: false,
    ),
    propertyName: 'id',
);

$example->raw;  // '4ccda740-74c3-4cfa-8571-ebf83c8f300a'
$example->node; // PhpParser\Node\Scalar\String_