zircote/swagger-php
Generate OpenAPI 3.0/3.1/3.2 docs from PHP 8.2+ code using attributes (preferred) or legacy Doctrine annotations. Includes CLI and programmatic APIs, extracts phpdoc metadata, provides helpful error reporting, and outputs ready-to-use specs.
Install via Composer (composer require zircote/swagger-php). Annotate your controller or DTO classes using @OA\ annotations (e.g., @OA\Get, @OA\Response, @OA\Property). Generate OpenAPI JSON/YAML using the Symfony Console-based CLI tool (php vendor/bin/openapi -o public/docs/openapi.json src/). For programmatic generation, use OpenApi\Generator::generate(). First use case: Document a REST endpoint with request/response examples and validation rules via annotations.
@OA\Get(path="/users") + @OA\Parameter, @OA\Response to describe HTTP behavior.@OA\Schema, @OA\Property, and @OA\Items to define typed request/response bodies.php vendor/bin/openapi in CI to validate schema consistency (now leveraging Symfony Console).Generator::scan(), and define global metadata via @OA\Info.int, string) are not auto-inferred; use @OA\Property(type="integer") explicitly.@OA\Property(ref="...") carefully or annotate with @OA\Discriminator.@OA\ annotations before PHPDoc comments (e.g., /** @var string */) to avoid conflicts.OpenApi\Analysis for custom processing (e.g., annotations, validation rules).--verbose with the CLI (php vendor/bin/openapi --verbose).OpenApi\Analysis::$lastError for parsing issues.bin/openapi tool now uses Symfony Console (PR #1977), enabling better error handling and flags (e.g., --help).ext-json dependency: The package no longer requires the JSON extension (PR #1974), reducing deployment friction.swagger-php version matches PHP version (v6.1.0+ requires PHP 8.0+).How can I help you explore Laravel packages today?