1. Go to this page and download the library: Download yiisoft/yii-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/ */
yiisoft / yii-swagger example snippets
use Yiisoft\DataResponse\Middleware\FormatDataResponseAsHtml;
use Yiisoft\DataResponse\Middleware\FormatDataResponseAsJson;
use Yiisoft\Router\Group;
use Yiisoft\Router\Route;
use Yiisoft\Swagger\Middleware\SwaggerUi;
use Yiisoft\Swagger\Action\SwaggerJson;
// Swagger routes
Group::create('/swagger', [
Route::get('')
->middleware(FormatDataResponseAsHtml::class)
->action(fn (SwaggerUi $swaggerUi) => $swaggerUi->withJsonUrl('/swagger/json-url')),
Route::get('/json-url')
->middleware(FormatDataResponseAsJson::class)
->action(SwaggerJson::class),
]),
use OpenApi\Annotations as OA;
/**
* @OA\Info(title="My first API", version="1.0")
*/
class DefaultController {
// ...
}