radebatz/openapi-router
最新稳定版本:3.1.0
Composer 安装命令:
composer require radebatz/openapi-router
包简介
Routing adapter for OpenApi annotations.
README 文档
README
Introduction
Allows to (re-)use Swagger-PHP attributes (docblock annotations are deprecated), to configure routes in the following frameworks:
Requirements
- PHP 8.1 or higher - depending on framework version.
Installation
You can use composer or simply download the release.
Composer
The preferred method is via composer. Follow the installation instructions if you do not already have composer installed.
Once composer is installed, execute the following command in your project root to install this library:
composer require radebatz/openapi-router
After that all required classes should be availabe in your project to add routing support.
Basic usage
Example using the Slim framework adapter and standard OpenApi attributes only.
Controller
<?php namespace MyApp\Controllers\V1; use OpenApi\Attributes as OA; use Radebatz\OpenApi\Extras\Attributes as OAX; /* Things shared by all endpoints in this controller.*/ #[OAX\Controller(prefix: '/api/v1')] #[OA\Response(response: 200, description: 'OK')] #[OAX\Middleware(names: ['auth', 'admin'])] class GetController { #[OA\Get(path: '/getme', operationId: 'getme')] #[OA\Response(response: 400, description: 'Not good enough')] public function getme($request, $response) { return $response->write('Get me'); } }
index.php
<?php use Radebatz\OpenApi\Routing\Adapters\SlimRoutingAdapter; use Radebatz\OpenApi\Routing\OpenApiRouter; use Slim\App; require '../vendor/autoload.php'; $app = new App(); (new OpenApiRouter([__DIR__ . '/../src/controllers'], new SlimRoutingAdapter($app))) ->registerRoutes(); $app->run();
Documentation
License
The openapi-router project is released under the MIT license.
统计信息
- 总下载量: 2.71k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2019-05-16