Home > PHP Framework > ThinkPHP > body text

thinkphp5 integrates Swagger-PHP (pitfall)

藏色散人
Release: 2020-09-07 09:22:53
forward
3672 people have browsed it

The following is the tutorial column of thinkphp to introduce thinkphp5 integrated Swagger-PHP (pitfall). I hope it will be helpful to friends in need!

thinkphp5 integrates Swagger-PHP (pitfall)

In the process of learning Swagger, I found that most of the information on the Internet is not particularly complete, so I specially posted a post to write down my troubleshooting process, hoping to be helpful to everyone.

1. Install swagger-php2.0

(Note: I downloaded swagger-php2.0, this article is for swagger-php2.0)

composer require zircote/swagger-php: 2.0.*
Copy after login

2. Download swagger-ui

Go to the swagger-ui official website to download the static page, and put the static page in the thinkphp framework directory, such as the public directory.

https://swagger.io/tools/swagger-ui/
Copy after login

3. The thinphp framework introduces swagger-php and generates the swagger.json file

use Swagger\Annotations as SWG;
class Index
{
public function index()
{
$swagger=\Swagger\scan(__DIR__);
$res=$swagger->saveAs('./swagger.json');
}
Copy after login

4. Document comment section

/**
* @SWG\Swagger(
* schemes={"http"},
* host="www.tp.com.cn/",
* basePath="/",
* @SWG\Info(
* title="API文档",
* version="1.0.0",
* )
* ),
*/
Copy after login

For detailed instructions on the use of Swgger-php, please visit

https://www.kancloud.cn/chengguang/swagger-php#/catalog
Copy after login

The above is the detailed content of thinkphp5 integrates Swagger-PHP (pitfall). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
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