Download the PHP package madong/swagger without Composer

On this page you can find all versions of the php package madong/swagger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package swagger

Madong Swagger 模块

PHP >= 8.1 OpenAPI 3.0 Webman

一个功能强大、结构清晰的 Swagger/OpenAPI 文档生成模块,专为 Webman 框架设计。

📋 目录

✨ 功能特性

📁 目录结构

命名空间规范

注解类型 命名空间 说明
响应注解 madong\swagger\annotation\response\* 只在 annotation 中,支持 IS_REPEATABLE
认证注解 madong\swagger\attribute\* 推荐使用的门面类
认证注解 madong\swagger\annotation\auth\* 实际实现(可用但不推荐)
操作注解 madong\swagger\annotation\operation\* 只在 annotation 中
Schema 注解 madong\swagger\annotation\schema\* 只在 annotation 中

重要:响应类(DataResponse、PageResponse 等)只在 annotation/response 中存在,没有对应的 attribute 版本。认证类则同时存在于 attribute 和 annotation/auth 中。

🚀 快速开始

1. 安装

2. 配置路由

在 app/adminapi/config/route.php 中注册 Swagger:

3. 创建 Schema

4. 在控制器中使用

5. 访问文档

启动服务后,访问:http://localhost:8787/adminapi/openapi

📚 注解分类详解

一、认证注解(attribute/ 或 annotation/auth/)

1. AllowAnonymous - 跳过认证

用于标记需要跳过 Token 验证或权限验证的接口。

推荐使用 attribute 命名空间:

属性说明:

2. Permission - 权限注解

用于标记控制器或方法需要的权限。

属性说明:

方法说明:

3. ValidationRule - 验证规则注解

用于在 Request 类的属性上定义验证规则,并可在 API 文档中展示验证信息。

属性说明:

方法说明:

二、响应注解(annotation/response/)

所有响应注解都支持 IS_REPEATABLE,可以在同一个方法上重复使用,用于定义不同状态码的响应。

1. DataResponse - 数据对象响应

返回单个数据对象的响应模板。

参数说明:

响应格式:

2. PageResponse - 分页响应

返回分页数据的响应模板。

响应格式:

3. ListResponse - 列表响应

返回列表数据的响应模板。

响应格式:

4. TreeResponse - 树形数据响应

返回树形数据的响应模板。

响应格式:

5. ResultResponse - 通用结果响应

返回通用结果的响应模板。

参数说明:

6. SimpleResponse - 简单响应

返回简单成功消息的响应模板。

响应格式:

三、操作注解(annotation/operation/)

1. ApiOperation - 操作信息

2. ApiParameter - 参数定义

3. ApiRequestBody - 请求体

🔧 AnnotationHelper 使用

AnnotationHelper 提供了一组便捷方法来获取控制器和方法的注解信息,主要用于中间件和文档生成。

基本用法

完整 API

获取注解

检查注解

实际应用场景

场景 1:权限中间件

场景 2:文档生成

场景 3:API 元数据收集

🔄 IS_REPEATABLE 支持

问题描述

在 PHP 8 中,属性默认不允许在同一个目标上重复使用。如果需要在同一个方法上定义多个响应(例如不同状态码的响应),会出现以下错误:

解决方案

本模块已为所有响应注解添加了 Attribute::IS_REPEATABLE 标志,支持在同一个方法上重复使用。

使用示例

支持 IS_REPEATABLE 的注解

所有响应注解都支持重复使用:

不支持重复的注解

以下注解不需要重复,因此不添加 IS_REPEATABLE 标志:

💡 最佳实践

1. 统一命名空间使用

推荐做法:

不推荐做法:

2. 合理使用响应注解重复

虽然支持重复,但建议根据实际业务需求合理使用:

推荐(2-3 个响应):

不推荐(过多响应):

3. 使用 ResponseHelper 简化代码

4. 权限注解的层级使用

类级别权限(作用于所有方法):

方法级别权限(覆盖或补充类级别):

5. 使用 ExampleHelper 生成示例数据

🔄 向后兼容

为了向后兼容,项目保留了 core\attribute 命名空间下的别名类:

兼容性说明

旧代码(继续有效):

新代码(推荐):

注意: 响应类(DataResponse、PageResponse 等)没有 core\attribute 别名,因为它们主要在控制器中使用,不需要被中间件频繁查询。

❓ 常见问题

Q1: 为什么响应类只在 annotation/response 中,没有 attribute 版本?

A: 响应类主要用于控制器文档注解,不需要被中间件频繁查询。认证类(AllowAnonymous/Permission)需要被中间件频繁查询,因此提供 attribute 门面简化使用。

Q2: 使用 attribute 和 annotation/auth 有什么区别?

A: 没有区别,attribute\* 类继承自 annotation\auth\* 类,两者完全等价。推荐使用 attribute 命名空间,更简洁。

Q3: AnnotationHelper 获取注解时应该用哪个类?

A: 推荐统一使用 attribute\* 类:

Q4: 为什么我的响应注解还是提示不能重复?

A: 请检查:

  1. 是否使用了正确的命名空间:

  2. 是否重新生成了自动加载:

  3. 是否更新了 vendor 目录:

Q5: 如何在中间件中获取注解?

A: 使用 AnnotationHelper:

Q6: 如何排除测试控制器不生成文档?

A: 在路由配置中排除:

📄 更新日志

v1.0.0 (2026-03-11)

新增功能

优化改进

文档完善

🤝 贡献

欢迎提交 Issue 和 Pull Request!

📄 许可证

MIT License

🙏 致谢

📞 联系方式


Made with ❤️ by Madong


All versions of swagger with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
webman-tech/swagger Version ^2.1
webman-tech/dto Version ^1.0
zircote/swagger-php Version ^5.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package madong/swagger contains the following files

Loading the files please wait ...