登录 注册

swagger-php

去点 Star
其他
5,304
Stars
0
Forks
0
Watchers
0
Open Issues
未知
许可证
PHP
语言
创建时间
最近更新

项目能做什么

用于解析和生成 Swagger 文档的 PHP 注解与解析库。
来源:AI 基于仓库事实生成 · 内容以仓库实际 README 为准

使用说明 查看原始 README 原仓库文档

中文使用说明暂未生成。下面保留原仓库 README 摘录,命令与配置均以原文为准。
原始 README 摘录(英文原文,节选前 3000 字符)
[![Build Status](https://img.shields.io/github/actions/workflow/status/zircote/swagger-php/build.yml?branch=master)](https://github.com/zircote/swagger-php/actions?query=workflow:build)
[![Total Downloads](https://img.shields.io/packagist/dt/zircote/swagger-php.svg)](https://packagist.org/packages/zircote/swagger-php)
[![License](https://img.shields.io/badge/license-Apache2.0-blue.svg)](LICENSE)

# swagger-php

Generate interactive [OpenAPI](https://www.openapis.org) documentation for your RESTful API
using [PHP attributes](https://www.php.net/manual/en/language.attributes.overview.php).

See the [documentation website](https://zircote.github.io/swagger-php/guide/spec-attributes) 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?](https://zircote.github.io/swagger-php/guide/why-spec).

## 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](https://getcomposer.org))

```shell
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.

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

### doctrine/annotations (deprecated)

As of version `4.8` the [doctrine annotations](https://www.doctrine-project.org/projects/annotations.html) library **is
optional** and **no longer installed by default**.

If your code uses doctrine annotations you will need to install that library manually:

```shell
composer require doctrine/annotations
```

## Usage

Use OpenAPI attributes to add metadata to your classes, methods and other structural PHP elements.

```php
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](https://zircote.github.io/swagger-php/) for
the [Getting started guide](https://zircote.github.io/swagger-php/guide) or look at
the [examples directory](docs/examples) for more examples.

### Classic attributes and docblock annotations

**Deprecated since 7.0, 
阅读完整原文

商业机会分析 AI 生成

基于 OpenAPI 的 PHP 专属 API 变更与破坏性检测 SaaS

产品构想利用 swagger-php 的 CLI/Builder 能力,在 GitHub Actions/GitLab CI 中自动解析 PR 前后的 OpenAPI 规范,检测 Breaking Changes 并生成可视化对比报告与 Mock 服务。
核心功能Git CI 插件、OpenAPI 差异分析引擎(推测)、破坏性更新警报、自动临时 Mock 服务生成、PR 评论通知。
目标用户采用 CI/CD 且对 API 向上兼容性要求高的中小团队、微服务团队。
难度/周期中等 · 1 - 2 个月 · 成本:极低(主要为云服务器与域名费用)
收费模式免费层限制项目数/调用频次,高级版按团队月付/年付 SaaS 订阅。
竞争风险通用 OpenAPI 差异检测工具(如 Optic、Buf)存在跨语言竞争,需专注 PHP 生态做深度定制集成。
依据 数据支持的判断

PhpStorm / VS Code 智能 OpenAPI Attribute 补全与可视化生成插件

产品构想针对 PHP 8.2+ Attributes 编写繁琐痛点,提供反向提取与一键补全工具,自动读取控制器入参/Docblock/DTO 并一键注入 swagger-php 属性。
核心功能从类型提示/方法返回值反向生成 #[OA\*] 属性、实时 OpenAPI JSON/YAML 侧边栏预览、属性合法性与嵌套校验。
目标用户重度使用 PhpStorm/VS Code 的 PHP 开发者、对编写大量 OpenAPI 注解感到低效的工程师。
难度/周期中等 · 1 - 3 个月 · 成本:极低(主要是开发者个人时间成本)
收费模式JetBrains Marketplace 付费插件模式(买断或年付订阅)。
竞争风险IDE 插件维护随 IDE 大版本升级有持续工作量,受众限定在付费愿望较强的专业开发者中。
依据 AI推测

PHP API 优先的多语言 SDK 自动构建与私有分发管道

产品构想基于 swagger-php 解析的 OpenAPI 规范,提供开箱即用的工作流服务,自动化编译 TypeScript、Swift、Kotlin 等多端类型安全的 SDK 并发布到私有仓储。
核心功能Swagger-php 输出规范化校验、代码生成引擎(生成 TS/Java/Swift 客户端)、私有包发布工作流(NPM/Composer/Maven)。
目标用户前后端分离紧密、同时维护移动端/前端应用但缺乏独立跨语言 SDK 维护团队的技术中台。
难度/周期较高 · 2 - 4 个月 · 成本:低(构建运行节点及存储)
收费模式按生成的 SDK 构建次数、托管私有包数量或坐席收费(SaaS 模式)。
竞争风险生成代码的规范性和类型安全度调优难度大,不同语言生态差异需要高适配成本。
依据 尚需验证的假设
AI 基于仓库公开数据分析生成,含推测成分,不构成收益承诺。
报告会保存到 个人中心

竞品与相似项目 GitHub Search 真实检索

项目中文简介Stars语言
cirosantilli/china-dictatorship 中文介绍暂未生成
反中共政治宣传库。Anti Chinese government propaganda. 住在中国真名用户的网友请别给星
3,333 HTML
DarkaOnLine/L5-Swagger 中文介绍暂未生成
OpenApi or Swagger integration to Laravel
2,934 PHP
nelmio/NelmioApiDocBundle 中文介绍暂未生成
Generates documentation for your REST API from attributes
2,381 PHP
gege-circle/.github 中文介绍暂未生成
这里是GitHub的草场,也是戈戈圈爱好者的交流地,主要讨论动漫、游戏、科技、人文、生活等所有话题,欢迎各位小伙伴们在此
2,093 -
caoym/phpboot 中文介绍暂未生成
:coffee: 🚀 tiny & fast PHP framework for building Microservi
649 PHP
cirosantilli/china-dictatroship-7 中文介绍暂未生成
反中共政治宣传库。Anti Chinese government propaganda. https://github.
389 HTML
以上为通过 GitHub 官方 Search API 检索的相似项目,功能差异与优劣势需进一步人工确认,配置 AI 后可生成对比分析。

项目优势与风险

技术成熟度创建于 ,最近推送 ,发布过 100 个 Release
社区活跃Star 5,304 / Fork 0 / Issue 0(数据支持,可自行核实)
许可证未检测到(需人工确认)
主要风险上游项目方向可能变化;同赛道竞争者较多(见竞品表);热度与需求不完全等价

安装与使用

快速开始(以仓库 README 为准)
git clone https://github.com/zircote/swagger-php.git
cd swagger-php
# 请阅读仓库 README 获取确切安装步骤(依赖、配置、启动命令)
阅读原仓库文档
术语说明:Docker=应用容器(把程序和依赖打包运行);API Key=调用外部服务的密钥;Git Clone=把仓库代码下载到本地。常见错误:API Key 未配置 / 端口占用 / 数据库连接失败,多数项目在 README 的 Troubleshooting 章节有说明。