swagger-php

Generate OpenAPI documentation for your PHP REST API from native PHP attributes or annotations.

Library
Composer
v6.6.0
5,306stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
94/100Excellent
Development Activity100
Maintenance96
Community80
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
82/100Excellent
Architecture88
Code Quality88
Innovation78
Learning Curve68

swagger-php generates interactive OpenAPI (formerly Swagger) documentation for RESTful APIs written in PHP. You describe your API using native PHP attributes (preferred) or Doctrine annotations placed alongside your code, and swagger-php scans the source to produce a compliant OpenAPI specification in JSON or YAML.

It supports the OpenAPI 3.0, 3.1, and 3.2 specifications, extracts information from existing PHPDoc, and can be run either programmatically via the Generator class or through the bundled openapi command-line tool. It is the parsing engine behind many Laravel and Symfony API-documentation packages.

What You Get

  • OpenAPI 3.0, 3.1, and 3.2 spec generation from PHP source
  • Native PHP attribute support (with legacy Doctrine annotation support)
  • A Generator class for programmatic use and a bin/openapi CLI tool
  • Extraction of details from existing PHPDoc and a processor pipeline for customization

Common Use Cases

  • Auto-generating OpenAPI specs from an annotated PHP REST API
  • Powering Swagger UI / interactive API docs in Laravel or Symfony apps
  • Producing an OpenAPI file in CI to publish or lint API contracts

Under The Hood

Architecture — The Generator orchestrates a pipeline: a SourceFinder collects PHP files, analysers (backed by nikic/php-parser and phpstan/phpdoc-parser) build an Analysis model of discovered annotations/attributes, a chain of Processors normalizes and links them (merging, augmenting, cleaning), and a Serializer emits the final OpenAPI document. Attribute and annotation classes under Attributes/Annotations model the spec; Console wires the bin/openapi CLI via Symfony Console.

Tech Stack — PHP 8.2+, depending on nikic/php-parser, phpstan/phpdoc-parser, symfony/console, symfony/finder, symfony/yaml, and psr/log. Output targets OpenAPI 3.0-3.2.

Code Quality — A large, mature, and actively maintained codebase (health 94) with clear separation between analysis, processing, and serialization, plus interfaces (CompilerInterface, TypeResolverInterface) for extensibility. It has an extensive test suite and strong CI.

API Design — The attribute-based API is expressive and reads close to the OpenAPI spec, and both the Generator programmatic entry point and the openapi CLI are straightforward. The main learning cost is the breadth of available attributes, mitigated by thorough documentation on the project’s website.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search