PHPackages                             avaibook-zircote/swagger-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. avaibook-zircote/swagger-php

ActiveLibrary[HTTP &amp; Networking](/categories/http)

avaibook-zircote/swagger-php
============================

swagger-php - Generate interactive documentation for your RESTful API using phpdoc annotations

4.7.3(3y ago)0199Apache-2.0PHPPHP &gt;=7.2

Since Apr 1Pushed 3y agoCompare

[ Source](https://github.com/avaibook/swagger-php)[ Packagist](https://packagist.org/packages/avaibook-zircote/swagger-php)[ Docs](https://github.com/zircote/swagger-php/)[ RSS](/packages/avaibook-zircote-swagger-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (10)Versions (119)Used By (0)

[![Build Status](https://camo.githubusercontent.com/15089156542f5f9c0a41a0dfb7df2df9056f77131ca73de6230dde0736ab3c0f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7a6972636f74652f737761676765722d7068702f6275696c642e796d6c3f6272616e63683d6d6173746572)](https://github.com/zircote/swagger-php/actions?query=workflow:build)[![Total Downloads](https://camo.githubusercontent.com/c2bb8bad151ca8f49df80908c1e6e796a05367f6df7a65864c87e5f4d9ba9231/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a6972636f74652f737761676765722d7068702e737667)](https://packagist.org/packages/zircote/swagger-php)[![License](https://camo.githubusercontent.com/caca0ef5422f17fb90c77a2f0bb083a8f8a4c71d2eb9545ef04ff01b00d7be62/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d417061636865322e302d626c75652e737667)](LICENSE)

swagger-php
===========

[](#swagger-php)

Generate interactive [OpenAPI](https://www.openapis.org) documentation for your RESTful API using [doctrine annotations](https://www.doctrine-project.org/projects/doctrine-annotations/en/latest/index.html).

For a full list of supported annotations, please have look at the [`OpenApi\Annotations` namespace](src/Annotations) or the [documentation website](https://zircote.github.io/swagger-php/guide/annotations.html).

Features
--------

[](#features)

- Compatible with the OpenAPI **3.0** and **3.1** specification.
- Extracts information from code &amp; existing phpdoc annotations.
- Command-line interface available.
- [Documentation site](https://zircote.github.io/swagger-php/) with a getting started guide.
- Exceptional error reporting (with hints, context)
- As of PHP 8.1 all annotations are also available as PHP attributes

OpenAPI version support
-----------------------

[](#openapi-version-support)

`swagger-php` allows to generate specs either for **OpenAPI 3.0.0** or **OpenAPI 3.1.0**. By default the spec will be in version `3.0.0`. The command line option `--version` may be used to change this to `3.1.0`.

Programmatically, the method `Generator::setVersion()` can be used to change the version.

Requirements
------------

[](#requirements)

`swagger-php` requires at least PHP 7.2 for annotations and PHP 8.1 for using attributes.

Installation (with [Composer](https://getcomposer.org))
-------------------------------------------------------

[](#installation-with-composer)

```
composer require zircote/swagger-php
```

For cli usage from anywhere install swagger-php globally and make sure to place the `~/.composer/vendor/bin` directory in your PATH so the `openapi` executable can be located by your system.

```
composer global require zircote/swagger-php
```

Usage
-----

[](#usage)

Add annotations to your php files.

```
/**
 * @OA\Info(title="My First API", version="0.1")
 */

/**
 * @OA\Get(
 *     path="/api/resource.json",
 *     @OA\Response(response="200", description="An example resource")
 * )
 */
```

Visit the [Documentation website](https://zircote.github.io/swagger-php/) for the [Getting started guide](https://zircote.github.io/swagger-php/guide) or look at the [Examples directory](Examples/) for more examples.

### Usage from php

[](#usage-from-php)

Generate always-up-to-date documentation.

```
