php swagger ui,thinkphp 集成swagger-ui

此种方法,不用每个项目都安装zircote/swagger-php,我觉得还是挺好的

1、全局安装zircote/swagger-php

composer global require zircote/swagger-php

2、配置环境变量(openapi路径)

export PATH="~/.composer/vendor/bin:${PATH}"

source ~/.bash_profile

3、随便找个目录下的php文件添加title信息

/**

* @OA\Info(title="health app API", version="2.0")

*/

4、生成yaml文件

打开终端运行openapi

JianLongs-MBP:~ jianlongnie$ openapi

Error: Specify at least one path.

Usage: openapi [--option value] [/path/to/project ...]

Options:

--output (-o) Path to store the generated documentation.

ex: --output openapi.yaml

--exclude (-e) Exclude path(s).

ex: --exclude vendor,library/Zend

--pattern (-n) Pattern of files to scan.

ex: --pattern "*.php" or --pattern "/\.(phps|php)$/"

--bootstrap (-b) Bootstrap a php file for defining constants, etc.

ex: --bootstrap config/constants.php

--processor Register an additional processor.

--format Force yaml or json.

--debug Show additional error information.

--help (-h) Display this help message.

进入项目根目录,运行:

openapi --output openapi.yaml app/api

生成的openyaml文件已经在项目根目录下面,

6157e9175f7a

image.png

5、配置swagger-ui,到这里我们已经生成了yaml文件,下一步就是如何显示的问题了,下载swagger-ui,

6157e9175f7a

image.png

下载完成之后,把这个文件件放到nginx或者apache服务器下面,打开里面的index.html修改yaml文件路径

6157e9175f7a

image.png

改为上一步我们生成好的yaml路径,然后访问服务器下面的index.html即可,像我的是

http://localhost:84/public/swagger-ui/index.html

注释方面的例子:

/**

* @OA\Post(

* path="/Register/mobile",

* summary="用户手机号注册",

* @OA\RequestBody(

* @OA\MediaType(

* mediaType="application/json",

* @OA\Schema(

* @OA\Property(

* property="mobile",

* type="string"

* ),

* @OA\Property(

* property="password",

* type="string"

* ),

* @OA\Property(

* property="code",

* type="string",

* description="验证码"

* ),

* @OA\Property(

* property="key",

* type="string",

* description="验证码key"

* ),

* example={"key":"register_mobile_code_78b48c4eb0b5c0a87522e89257b79c38","mobile": "+12103841215", "password": "NJLd123456","code":"1111"}

* )

* )

* ),

* @OA\Response(

* response=200,

* description="OK"

* )

* )

*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值