php-swagger安装和使用

swagger是java的一个接口调试工具,phper模仿他写了php-swagger

composer require zircote/swagger-php

我用的tp5.0,打开项目主目录, 找到可执行文件openapi,也可以在Examples中找到例子,照着写就可以了

  • 生成yaml指令
  • 我在主目录的docs-dev中写编译前的注释文件,在public/docs中存放编译后的yaml文件
php ./vendor/zircote/bin/openapi ./docs-dev/ -o ./public/docs
  • 使用swagger-ui

github:https://github.com/swagger-api/swagger-ui

可以通过npm导入模块,我直接用的github克隆下来使用

cd public
git clone https://github.com/swagger-api/swagger-ui

克隆完成后,找到index.html,配置yaml文件路径 

在42行配置好yaml文件路径即可

 然后输入自己的测试服务器配置好的网址就可以访问了,例如我的服务器

 swagger可以像 postman一样直接调试哦,非常方便

原文地址:https://www.cnblogs.com/YC-L/p/12640216.html