PHP code example of zircote / swagger-php

1. Go to this page and download the library: Download zircote/swagger-php 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/ */

    

zircote / swagger-php example snippets



use OpenApi\Attributes as OAT;

#[OAT\Info(title: 'My First API', version: '0.1')]
class MyApi
{
    #[OAT\Get(path: '/api/resource.json')]
    #[OAT\Response(response: '200', description: 'An example resource')]
    public function getResource()
    {
        // ...
    }
}


api = (new \OpenApi\Generator())->generate(['/path/to/project']);
header('Content-Type: application/x-yaml');
echo $openapi->toYaml();

class MyClass
{
    #[OAT\Property(items: new OAT\Items(oneOf: [
        new OAT\Schema(type: SchemaOne::class),
        new OAT\Schema(type: SchemaTwo::class),
    ]))]
    public array $values;
}

class MyClass
{
    /**
     * @var list<SchemaOne|SchemaTwo>
     */
    public array $values;
}
shell
composer 
shell
composer global