Home > Backend Development > PHP Tutorial > PHP使用 swagger 自动生成 API 文档

PHP使用 swagger 自动生成 API 文档

不言
Release: 2023-02-28 15:28:01
Original
8597 people have browsed it

使用 swagger 自动生成 API 文档

使用 swagger 自动生成 API 文档,有需要的朋友可以参考下。

      一、下载 swagger-ui 直接上传服务器

      二、下载 swagger-php 根据文档进行安装

      三、PHP文件添加注释代码

/** 
* @SWG/Resource ( 
* apiVersion = "版本号", 
* basePath = "API地址", 
* resourcePath ="项目名称", 
* @SWG/Api ( 
* path = "API文件名", 
* description = "功能描述", 
* @SWG/Operation ( 
* method="POST", summary="操作描述", nickname = "显示名", 
* @SWG/Parameter (name="参数名", description="参数说明", required = true, paramType = "query", type="string"), 
* @SWG/ResponseMessage (code=200, message="返回说明") 
* ) 
* ) 
*) 
*/
Copy after login

      四、使用swager-php 生成JSON地址

php ../composer/vendor/zircote/swagger-php/swagger.phar /apifolder -o /docfolder

      五、修改swagger-ui 默认数据地址

      六、Done

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template