1. Install with composer:#
> composer require --dev zircote/swagger-php
2. Update your code#
Add swagger-php annotations or attributes to your source code.
Annotations
Attributes
<?php
use OpenApiAnnotations as OA;
/**
* @OAInfo(
* title="My First API",
* version="0.1"
* )
*/
class OpenApi {}
class MyController {
/**
* @OAGet(
* path="/api/data.json",
* @OAResponse(
* response="200",
* description="The data"
* )
* )
*/
public function getResource() {
// ...
}
}
3. Generate OpenAPI documentation#
> ./bin/openapi src -o openapi.yaml
4. Explore and interact with your API#
Use an OpenAPI tool like Swagger UI to explore and interact with your API.