|
1 |
| -# imi-apidoc |
2 |
| - |
3 |
| -[](https://packagist.org/packages/imiphp/imi-apidoc) |
4 |
| -[](https://secure.php.net/) |
5 |
| -[](https://github.com/swoole/swoole-src) |
6 |
| -[](https://github.com/imiphp/imi-apidoc/blob/master/LICENSE) |
7 |
| - |
8 |
| -## 介绍 |
9 |
| - |
10 |
| -支持在项目中使用 Swagger 注解语法,运行命令,生成 Swagger 文件。 |
11 |
| - |
12 |
| -Swagger 是最流行的 API 开发工具,它遵循 OpenAPI Specification(OpenAPI 规范,也简称 OAS)。 |
13 |
| - |
14 |
| -Swagger 可以贯穿于整个 API 生态,如 API 的设计、编写 API 文档、测试和部署。 |
15 |
| - |
16 |
| -Swagger 是一种通用的,和编程语言无关的 API 描述规范。 |
17 |
| - |
18 |
| -imi-apidoc 基于 [zircote/swagger-php](https://github.com/zircote/swagger-php) 开发,100% 支持写法。 |
19 |
| - |
20 |
| -## Composer |
21 |
| - |
22 |
| -本项目可以使用composer安装,遵循psr-4自动加载规则,在你的 `composer.json` 中加入下面的内容: |
23 |
| - |
24 |
| -```json |
25 |
| -{ |
26 |
| - "require": { |
27 |
| - "imiphp/imi-apidoc": "^1.0.0" |
28 |
| - } |
29 |
| -} |
30 |
| -``` |
31 |
| - |
32 |
| -然后执行 `composer update` 安装。 |
33 |
| - |
34 |
| -## 使用说明 |
35 |
| - |
36 |
| -> 可以参考 `example`、`tests` 目录示例。 |
37 |
| -
|
38 |
| -项目配置文件: |
39 |
| - |
40 |
| -```php |
41 |
| -[ |
42 |
| - 'components' => [ |
43 |
| - 'ApiDoc' => 'Imi\ApiDoc', |
44 |
| - ], |
45 |
| -] |
46 |
| -``` |
47 |
| - |
48 |
| -Swagger 书写文档说明:<https://zircote.github.io/swagger-php/Getting-started.html#annotation-placement> |
49 |
| - |
50 |
| -**Demo:** |
51 |
| - |
52 |
| -```php |
53 |
| -<?php |
54 |
| -namespace ImiApp\ApiServer\Controller; |
55 |
| - |
56 |
| -use Imi\Server\Route\Annotation\Route; |
57 |
| -use Imi\Server\Route\Annotation\Action; |
58 |
| -use Imi\Controller\SingletonHttpController; |
59 |
| -use Imi\Server\Route\Annotation\Controller; |
60 |
| - |
61 |
| -/** |
62 |
| - * @OA\Info(title="My First API", version="0.1") |
63 |
| - * @Controller("/") |
64 |
| - */ |
65 |
| -class IndexController extends SingletonHttpController |
66 |
| -{ |
67 |
| - /** |
68 |
| - * @Action |
69 |
| - * @Route("/") |
70 |
| - * |
71 |
| - * |
72 |
| - * @return void |
73 |
| - */ |
74 |
| - public function index() |
75 |
| - { |
76 |
| - |
77 |
| - } |
78 |
| - |
79 |
| - /** |
80 |
| - * @Action |
81 |
| - * @Route(url="login", method="POST") |
82 |
| - * |
83 |
| - * @param string $username 用户名 |
84 |
| - * @param integer $password 密码 |
85 |
| - * |
86 |
| - * @return void |
87 |
| - */ |
88 |
| - public function login(string $username, int $password) |
89 |
| - { |
90 |
| - |
91 |
| - } |
92 |
| - |
93 |
| - /** |
94 |
| - * @Action |
95 |
| - * @Route("register") |
96 |
| - * @OA\Get( |
97 |
| - * path="/register", |
98 |
| - * @OA\Response(response="200", description="An example resource") |
99 |
| - * ) |
100 |
| - * |
101 |
| - * @param string $username 用户名 |
102 |
| - * @param integer $password 密码 |
103 |
| - * @param string $birthday 生日 |
104 |
| - * |
105 |
| - * @return void |
106 |
| - */ |
107 |
| - public function register(string $username, int $password |
108 |
| - , string $birthday) |
109 |
| - { |
110 |
| - |
111 |
| - } |
112 |
| - |
113 |
| - /** |
114 |
| - * @Action |
115 |
| - * |
116 |
| - * @param int $id |
117 |
| - * @return void |
118 |
| - */ |
119 |
| - public function get(int $id) |
120 |
| - { |
121 |
| - |
122 |
| - } |
123 |
| - |
124 |
| -} |
125 |
| -``` |
126 |
| - |
127 |
| -imi-apidoc 会根据 `@Route` 注解、`@param` 注释,自动补足相关信息。让你不必为每个接口都书写 Swagger 注解,提升开发效率。 |
128 |
| - |
129 |
| -当然,如果希望更加个性化的信息设置,还是要自己去书写的! |
130 |
| - |
131 |
| -**生成命令:** |
132 |
| - |
133 |
| -Yaml 格式: `imi doc/api -to api.yml` |
134 |
| - |
135 |
| -Json 格式: `imi doc/api -to api.json` |
136 |
| - |
137 |
| -指定扫描的命名空间:`imi doc/api -to api.json -namespace "ImiApp\Controller1,ImiApp\Controller2"` |
138 |
| - |
139 |
| -**效果:** |
140 |
| - |
141 |
| -<img src="https://raw.githubusercontent.com/imiphp/imi-apidoc/master/res/1.jpg"/> |
142 |
| - |
143 |
| -<img src="https://raw.githubusercontent.com/imiphp/imi-apidoc/master/res/2.jpg"/> |
144 |
| - |
145 |
| -## 免费技术支持 |
146 |
| - |
147 |
| -QQ群:17916227 [](https://jq.qq.com/?_wv=1027&k=5wXf4Zq),如有问题会有人解答和修复。 |
148 |
| - |
149 |
| -## 运行环境 |
150 |
| - |
151 |
| -- [PHP](https://php.net/) >= 7.1 |
152 |
| -- [Composer](https://getcomposer.org/) |
153 |
| -- [Swoole](https://www.swoole.com/) >= 4.3.0 |
154 |
| - |
155 |
| -## 版权信息 |
156 |
| - |
157 |
| -`imi-apidoc` 遵循 MIT 开源协议发布,并提供免费使用。 |
158 |
| - |
159 |
| -## 捐赠 |
160 |
| - |
161 |
| -<img src="https://raw.githubusercontent.com/imiphp/imi-apidoc/master/res/pay.png"/> |
162 |
| - |
163 |
| -开源不求盈利,多少都是心意,生活不易,随缘随缘…… |
| 1 | +# imi-apidoc |
| 2 | + |
| 3 | +[](https://packagist.org/packages/imiphp/imi-apidoc) |
| 4 | +[](https://secure.php.net/) |
| 5 | +[](https://github.com/swoole/swoole-src) |
| 6 | +[](https://github.com/imiphp/imi-apidoc/blob/master/LICENSE) |
| 7 | + |
| 8 | +## 介绍 |
| 9 | + |
| 10 | +支持在项目中使用 Swagger 注解语法,运行命令,生成 Swagger 文件。 |
| 11 | + |
| 12 | +Swagger 是最流行的 API 开发工具,它遵循 OpenAPI Specification(OpenAPI 规范,也简称 OAS)。 |
| 13 | + |
| 14 | +Swagger 可以贯穿于整个 API 生态,如 API 的设计、编写 API 文档、测试和部署。 |
| 15 | + |
| 16 | +Swagger 是一种通用的,和编程语言无关的 API 描述规范。 |
| 17 | + |
| 18 | +imi-apidoc 基于 [zircote/swagger-php](https://github.com/zircote/swagger-php) 开发,100% 支持写法。 |
| 19 | + |
| 20 | +> 本仓库仅用于浏览,不接受 issue 和 Pull Requests,请前往:<https://github.com/Yurunsoft/imi> |
| 21 | +
|
| 22 | +## Composer |
| 23 | + |
| 24 | +本项目可以使用composer安装,遵循psr-4自动加载规则,在你的 `composer.json` 中加入下面的内容: |
| 25 | + |
| 26 | +```json |
| 27 | +{ |
| 28 | + "require": { |
| 29 | + "imiphp/imi-apidoc": "^1.0.0" |
| 30 | + } |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +然后执行 `composer update` 安装。 |
| 35 | + |
| 36 | +## 使用说明 |
| 37 | + |
| 38 | +> 可以参考 `example`、`tests` 目录示例。 |
| 39 | +
|
| 40 | +项目配置文件: |
| 41 | + |
| 42 | +```php |
| 43 | +[ |
| 44 | + 'components' => [ |
| 45 | + 'ApiDoc' => 'Imi\ApiDoc', |
| 46 | + ], |
| 47 | +] |
| 48 | +``` |
| 49 | + |
| 50 | +Swagger 书写文档说明:<https://zircote.github.io/swagger-php/Getting-started.html#annotation-placement> |
| 51 | + |
| 52 | +**Demo:** |
| 53 | + |
| 54 | +```php |
| 55 | +<?php |
| 56 | +namespace ImiApp\ApiServer\Controller; |
| 57 | + |
| 58 | +use Imi\Server\Route\Annotation\Route; |
| 59 | +use Imi\Server\Route\Annotation\Action; |
| 60 | +use Imi\Controller\SingletonHttpController; |
| 61 | +use Imi\Server\Route\Annotation\Controller; |
| 62 | + |
| 63 | +/** |
| 64 | + * @OA\Info(title="My First API", version="0.1") |
| 65 | + * @Controller("/") |
| 66 | + */ |
| 67 | +class IndexController extends SingletonHttpController |
| 68 | +{ |
| 69 | + /** |
| 70 | + * @Action |
| 71 | + * @Route("/") |
| 72 | + * |
| 73 | + * |
| 74 | + * @return void |
| 75 | + */ |
| 76 | + public function index() |
| 77 | + { |
| 78 | + |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * @Action |
| 83 | + * @Route(url="login", method="POST") |
| 84 | + * |
| 85 | + * @param string $username 用户名 |
| 86 | + * @param integer $password 密码 |
| 87 | + * |
| 88 | + * @return void |
| 89 | + */ |
| 90 | + public function login(string $username, int $password) |
| 91 | + { |
| 92 | + |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * @Action |
| 97 | + * @Route("register") |
| 98 | + * @OA\Get( |
| 99 | + * path="/register", |
| 100 | + * @OA\Response(response="200", description="An example resource") |
| 101 | + * ) |
| 102 | + * |
| 103 | + * @param string $username 用户名 |
| 104 | + * @param integer $password 密码 |
| 105 | + * @param string $birthday 生日 |
| 106 | + * |
| 107 | + * @return void |
| 108 | + */ |
| 109 | + public function register(string $username, int $password |
| 110 | + , string $birthday) |
| 111 | + { |
| 112 | + |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * @Action |
| 117 | + * |
| 118 | + * @param int $id |
| 119 | + * @return void |
| 120 | + */ |
| 121 | + public function get(int $id) |
| 122 | + { |
| 123 | + |
| 124 | + } |
| 125 | + |
| 126 | +} |
| 127 | +``` |
| 128 | + |
| 129 | +imi-apidoc 会根据 `@Route` 注解、`@param` 注释,自动补足相关信息。让你不必为每个接口都书写 Swagger 注解,提升开发效率。 |
| 130 | + |
| 131 | +当然,如果希望更加个性化的信息设置,还是要自己去书写的! |
| 132 | + |
| 133 | +**生成命令:** |
| 134 | + |
| 135 | +Yaml 格式: `imi doc/api -to api.yml` |
| 136 | + |
| 137 | +Json 格式: `imi doc/api -to api.json` |
| 138 | + |
| 139 | +指定扫描的命名空间:`imi doc/api -to api.json -namespace "ImiApp\Controller1,ImiApp\Controller2"` |
| 140 | + |
| 141 | +**效果:** |
| 142 | + |
| 143 | +<img src="https://raw.githubusercontent.com/imiphp/imi-apidoc/master/res/1.jpg"/> |
| 144 | + |
| 145 | +<img src="https://raw.githubusercontent.com/imiphp/imi-apidoc/master/res/2.jpg"/> |
| 146 | + |
| 147 | +## 免费技术支持 |
| 148 | + |
| 149 | +QQ群:17916227 [](https://jq.qq.com/?_wv=1027&k=5wXf4Zq),如有问题会有人解答和修复。 |
| 150 | + |
| 151 | +## 运行环境 |
| 152 | + |
| 153 | +- [PHP](https://php.net/) >= 7.1 |
| 154 | +- [Composer](https://getcomposer.org/) |
| 155 | +- [Swoole](https://www.swoole.com/) >= 4.3.0 |
| 156 | + |
| 157 | +## 版权信息 |
| 158 | + |
| 159 | +`imi-apidoc` 遵循 MIT 开源协议发布,并提供免费使用。 |
| 160 | + |
| 161 | +## 捐赠 |
| 162 | + |
| 163 | +<img src="https://cdn.jsdelivr.net/gh/Yurunsoft/IMI@dev/res/pay.png"/> |
| 164 | + |
| 165 | +开源不求盈利,多少都是心意,生活不易,随缘随缘…… |
0 commit comments