Home > Article > PHP Framework > thinkphp5 integrates Swagger-PHP (pitfall)
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!

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.*
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/
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');
}4. Document comment section
/**
* @SWG\Swagger(
* schemes={"http"},
* host="www.tp.com.cn/",
* basePath="/",
* @SWG\Info(
* title="API文档",
* version="1.0.0",
* )
* ),
*/For detailed instructions on the use of Swgger-php, please visit
https://www.kancloud.cn/chengguang/swagger-php#/catalog
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!