OpenAPI conformant
Generate OpenAPI documents in version 3.0 or 3.1.
![]() |
VOOZH | about |
Generate OpenAPI documents in version 3.0 or 3.1.
Using swagger-php lets you write the API documentation inside the PHP source files which helps keeping the documentation up-to-date.
Annotations can be either docblocks or PHP 8.1 attributes.
> composer require zircote/swagger-phpAdd swagger-php attributes (or legacy annotations) to your source code.
⚠️ The doctrine/annotations library used to parse annotation is going to be deprecated, so wherever possible attributes should be used.
<?php
namespace Openapi\Snippets\MinimalApi;
use OpenApi\Attributes as OA;
#[OA\Info(title: 'My First API', version: '0.1')]
class OpenApi
{
}
class MyController
{
#[OA\Get(path: '/api/data.json', operationId: 'getData')]
#[OA\Response(response: '200', description: 'The data')]
public function getResource()
{
// ...
}
}<?php
namespace Openapi\Snippets\MinimalApi;
use OpenApi\Annotations as OA;
/**
* @OA\Info(
* title="My First API",
* version="0.1"
* )
*/
class OpenApi
{
}
class MyController
{
/**
* @OA\Get(
* path="/api/data.json",
* operationId="getData",
* @OA\Response(
* response="200",
* description="The data"
* )
* )
*/
public function getResource()
{
// ...
}
}> ./vendor/bin/openapi src -o openapi.yamlUse an OpenAPI tool like Swagger UI or Scalar to explore and interact with your API.