genxoft / yii2-oas3
Yii2 Open Api Swagger 3 集成
v0.2-stable
2019-09-24 08:11 UTC
Requires
- php: >=7.1
- ext-json: *
- bower-asset/swagger-ui: ^3.20
- yiisoft/yii2: ~2.0
- zircote/swagger-php: ^3.0
This package is auto-updated.
Last update: 2024-09-24 19:52:34 UTC
README
要求
- PHP 7.1
- Yii2 框架
安装
安装此包装器的首选方式是通过 composer.
php composer.phar require genxoft/yii2-oas3 "*"
或者
composer require genxoft/yii2-oas3 "*"
或者将其添加到 composer.json
的 require 部分
"genxoft/yii2-oas3" : "*"
集成
向 Web 控制器添加操作(例如 SiteController.php)
public function actions() { return [ 'api-docs' => [ 'class' => 'genxoft\swagger\ViewAction', 'apiJsonUrl' => \yii\helpers\Url::to(['/site/api-json'], true), ], 'api-json' => [ 'class' => 'genxoft\swagger\JsonAction', 'dirs' => [ Yii::getAlias('@api/modules/api/controllers'), Yii::getAlias('@api/modules/api/models'), Yii::getAlias('@api/models'), ], ], ]; }
Open Api Swagger 3 示例注解
API 服务器描述
/** * @OA\Info( * version="1.0", * title="Application API", * description="Server - Mobile app API", * @OA\Contact( * name="John Smith", * email="john@example.com", * ), * ), * @OA\Server( * url="https://example.com/api", * description="main server", * ) * @OA\Server( * url="https://dev.example.com/api", * description="dev server", * ) */ class DefaultController extends Controller { ...
控制器注解
/** * @OA\Get(path="/", * summary="Handshake", * tags={"handshake"}, * @OA\Parameter( * name="access-token", * in="header", * required=false, * @OA\Schema( * type="string" * ) * ), * @OA\Response( * response=200, * description="Returns Hello object", * @OA\MediaType( * mediaType="application/json", * @OA\Schema(ref="#/components/schemas/Hello"), * ), * ), * ) */ public function actionIndex() { ...
模型注解
/** *@OA\Schema( * schema="Hello", * @OA\Property( * property="message", * type="string", * description="Text message" * ), * @OA\Property( * property="time", * type="integer", * description="Server current Unix time" * ), * @OA\Property( * property="date", * type="string", * format="date-time", * description="Server current date time" * ) *) */ class Hello extends Model { ...
捐赠
许可协议
此 curl 包装器根据 MIT 许可协议 发布。