PHP code example of eugene-erg / open-api

1. Go to this page and download the library: Download eugene-erg/open-api 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/ */

    

eugene-erg / open-api example snippets




declare(strict_types = 1);

use EugeneErg\OpenApi\Builder;
use EugeneErg\OpenApi\Components;
use EugeneErg\OpenApi\Components\Parameters;
use EugeneErg\OpenApi\Components\RequestBodies;
use EugeneErg\OpenApi\Components\Responses;
use EugeneErg\OpenApi\Components\Schemas;
use EugeneErg\OpenApi\Info;
use EugeneErg\OpenApi\Openapi;
use EugeneErg\OpenApi\Paths;
use EugeneErg\OpenApi\Servers;

$error = new Schemas\Object\Schema(
    properties: new Schemas\Object\Properties(
        code: new Schemas\Object\Property(
            schema: new Schemas\Integer\Schema(
                format: Schemas\Integer\Format::Int32,
            ),
            as\Object\Properties(
        id: new Schemas\Object\Property(
            schema: new Schemas\Integer\Schema(
                format: Schemas\Integer\Format::Int64,
            ),
            n: 'Entity not found.',
);

$category = new Schemas\Object\Schema(
    properties: new Schemas\Object\Properties(
        id:  new Schemas\Object\Property(
            schema: new Schemas\Integer\Schema(
                format: Schemas\Integer\Format::Int64,
            ),
            rs\Query\Queries($categoryFilter, $priceRange),
                ),
            ),
        ),
    ]),
    components: new Components(
        schemas: new Schemas\Untyped\Schemas(
            Product: $product,
            Category: $category,
            Error: $error,
        ),
        responses: new Responses(
            NotFound: $notFound,
            GeneralError: $generalError,
        ),
        parameters: new Parameters(
            categoryFilter: new Parameters\Parameter(
                name: 'category',
                parameter: $categoryFilter,
            ),
            priceRange: new Parameters\Parameter(
                name: 'priceRange',
                parameter: $priceRange,
            ),
        ),
    ),
    servers: new Servers(
        new Servers\Server(
            url: 'https://api.advancedexample.com/v1',
            description: 'Main server',
        ),
    ),
);

/** @var array<string<fileName>, stdClass<OpenapiConfig>> $results */
$results = (new Builder($openapi))->prepareToSave('path/directory');