swagger-php

一个 php swagger 注解和解析库。(A php swagger annotation and parsing library)

Github星跟蹤圖

Build Status
Total Downloads
License

swagger-php

Generate interactive OpenAPI documentation for your RESTful API using doctrine annotations.

Features

  • Compatible with the OpenAPI 3.0 specification.
  • Extracts information from code & existing phpdoc annotations.
  • Command-line interface available.
  • Documentation site with a getting started guide.
  • Exceptional error reporting (with hints, context)

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

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 for the Getting started guide or look at the Examples directory for more examples.

Usage from php

Generate always-up-to-date documentation.

<?php
require("vendor/autoload.php");
$openapi = \OpenApi\scan('/path/to/project');
header('Content-Type: application/x-yaml');
echo $openapi->toYaml();

Usage from the Command Line Interface

Generate the documentation to a static json file.

./vendor/bin/openapi --help

Usage from the Deserializer

Generate the OpenApi annotation object from a json string, which makes it easier to manipulate objects programmatically.

<?php

use OpenApi\Serializer;

$serializer = new Serializer();
$openapi = $serializer->deserialize($jsonString, 'OpenApi\Annotations\OpenApi');
echo $openapi->toJson();

Usage from docker

Generate the swagger documentation to a static json file.

docker run -v "$PWD":/app -it tico/swagger-php --help

More on OpenApi & Swagger

Contributing

Feel free to submit Github Issues
or pull requests.

The documentation website is build from the docs folder with vuepress.

Make sure pull requests pass PHPUnit
and PHP_CodeSniffer (PSR-2) tests.

To run both unittests and linting execute:

composer test

Running only unittests:

./bin/phpunit

Running only linting:

./bin/phpcs -p --extensions=php --standard=PSR2 --error-severity=1 --warning-severity=0 ./src ./tests

主要指標

概覽
名稱與所有者zircote/swagger-php
主編程語言PHP
編程語言PHP (語言數: 1)
平台Linux, Mac, Windows
許可證Apache License 2.0
所有者活动
創建於2012-03-24 23:13:26
推送於2025-10-27 12:40:48
最后一次提交2025-10-27 12:40:08
發布數172
最新版本名稱5.5.2 (發布於 )
第一版名稱0.1.0 (發布於 2012-04-19 11:27:15)
用户参与
星數5.3k
關注者數93
派生數0.9k
提交數852
已啟用問題?
問題數1040
打開的問題數31
拉請求數603
打開的拉請求數6
關閉的拉請求數180
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?