Allows to (re-)use Swagger-PHP annotations to configure routes in the following frameworks:
- PHP 7.2 or higher - depending on framework version.
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.
Example using the Slim
framework adapter and standard OpenApi annotations only.
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();
Controller
<?php
namespace MyApp\Controllers;
class GetController
{
/**
* @OA\Get(
* path="/getme",
* x={
* "name": "getme"
* },
* @OA\Response(response="200", description="All good")
* )
*/
public function getme($request, $response) {
return $response->write('Get me');
}
}
The openapi-router project is released under the MIT license.