1. Go to this page and download the library: Download fgh151/yii2-swagger library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fgh151 / yii2-swagger example snippets
'modules' => [
'swagger' => [
'class' => fgh151\swagger\Module::class,
'sources' => [
dirname(__DIR__).'/controllers', //here can be aliases, like '@app/controllers'
dirname(__DIR__).'/models',
],
'schema' => '/api/schema', //optional depend on route config
],
],
namespace app\controllers;
use OpenApi\Attributes\Info;
use OpenApi\Attributes\OpenApi;
use OpenApi\Attributes\Server;
use yii\web\Controller;
#[OpenApi(
info: new Info(version: '1.0.0', title: 'Super API title'),
)]
#[Server(url: 'https://api.example.com', description: 'Super API description')]
class SwaggerController extends Controller
{
}
class SomeController extends \yii\web\Controller {
#[Get(path: '/magic', summary: 'Magic API method.')]
public function someAction() {
//Magic here
}
}