Trên GitHub, zircote/swagger-php đã đạt 5.3k sao, ngôn ngữ PHP. A php swagger annotation and parsing library
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Generate interactive OpenAPI documentation for your RESTful API
using PHP attributes.
See the documentation website for supported
attributes.
Features
Compatible with the OpenAPI 3.0, 3.1 and 3.2 specification.
Extracts information from code and existing phpdoc comments.
Can be used programmatically or via command-line tool.
Error reporting (with hints, context).
Spec attributes: attributes that can also be built by hand and compiled without scanning, and a pipeline that reports when an attribute is wrong. See Why spec attributes?.
OpenAPI version support
swagger-php can generate specs for OpenAPI 3.0.0, OpenAPI 3.1.0 and OpenAPI 3.2.0.
Classic mode defaults to 3.0.0, spec and hybrid mode to 3.1.0.
The command line option --version selects a different version; programmatically, use
Builder::setVersion().
Requirements
swagger-php requires at least PHP 8.2.
Installation (with Composer)
composer require zircote/swagger-php
For cli usage from anywhere, install swagger-php globally and add Composer's global binary directory
(composer global config bin-dir --absolute) to your PATH, so the openapi executable can be located by
your system.
composer global require zircote/swagger-php
doctrine/annotations (deprecated)
As of version 4.8 the doctrine annotations library is
optional and no longer installed by default.
If your code uses doctrine annotations you will need to install that library manually:
composer require doctrine/annotations
Usage
Use OpenAPI attributes to add metadata to your classes, methods and other structural PHP elements.
use OpenApi\Spec as OA;
#[OA\Info(title: 'My First API', version: '0.1')]
class MyApi
{
#[OA\Operation\Get(path: '/api/resource.json')]
#[OA\Response(response: 200, description: 'An example resource')]
public function getResource()
{
// ...
}
}
Visit the Documentation website for
the Getting started guide or look at
the examples directory for more examples.
Classic attributes and docblock annotations
Deprecated since 7.0, removed in 8.0.
Classic attributes in OpenApi\Attributes and docblock annotations still work, in hybrid and in classic
mode. Hybrid, the default, scans them and hands them to the same pipeline as the attributes above.
Classic mode builds them with its own pipeline, as in 6.x.
use OpenApi\Attributes as OAT;
#[OAT\Info(title: 'My First API', version: '0.1')]
class MyApi
{
#[OAT\Get(path: '/api/resource.json')]
#[OAT\Response(response: '200', description: 'An example resource')]
public function getResource()
{
// ...
}
}
Migrating to spec attributes covers the move,
and Processing Modes compares the modes.
Builder is the entry point, and one instance builds one document.
See the Builder reference for its API.
Details on how to generate OpenApi specifications can be found
in the generate reference.
Usage from the Command Line Interface
The openapi command line interface can be used to generate the documentation to a static yaml/json file.
./vendor/bin/openapi --help
Automatic type resolution
Types are resolved with the symfony/type-info library. swagger-php supports all native type hints and also
generic type hints in phpdoc blocks. This simplifies the definition of schemas.
For example, the following two examples are equivalent:
class MyClass
{
#[OA\Schema\Items(oneOf: [
new OA\Schema(ref: SchemaOne::class),
new OA\Schema(ref: SchemaTwo::class),
])]
public array $values;
}
class MyClass
{
/**
* @var list<SchemaOne|SchemaTwo>
*/
#[OA\Property]
public array $values;
}
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/zircote/swagger-php là nguồn chính thức.
zircote/swagger-php có bao nhiêu sao?
zircote/swagger-php có 5.3k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/zircote/swagger-php. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
zircote/swagger-php có phải mã nguồn mở không?
Có — zircote/swagger-php phát hành theo license Apache-2.0, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/zircote/swagger-php.
zircote/swagger-php có trang demo không?
Dự án có trang chủ ở http://zircote.github.io/swagger-php/. Tab "Readme" ở trang này thường có ảnh chụp và hướng dẫn bắt đầu nhanh.
zircote/swagger-php là gì?
zircote/swagger-php (zircote/swagger-php) là dự án PHP trên GitHub. Theo mô tả gốc: A php swagger annotation and parsing library
Đọc đầy đủ README ở tab phía trên.
swagger-php có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về swagger-php.