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()
{
// ...
}
}
use OpenApi\Spec as OA;
#[OA\OpenApi(version: '3.1.0')]
#[OA\Info(title: 'My API', version: '1.0')]
class MyApi
{
#[OA\Operation\Get(path: '/api/resource')]
#[OA\Response(response: 200, description: 'An example resource')]
public function getResource() {}
}
$result = (new \OpenApi\Builder())
->setMode(\OpenApi\Builder\Mode::SPEC)
->addSource('src/')
->build();
$result = (new \OpenApi\Builder())
->setMode(\OpenApi\Builder\Mode::HYBRID)
->addSource('src/')
->build();
lt = (new \OpenApi\Builder())
->addSource(['/path/to/project'])
->build();
header('Content-Type: application/x-yaml');
echo $result->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
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.