radebatz / openapi-router
Routing adapter for OpenApi annotations.
Requires
- php: >=7.2
- doctrine/annotations: ^1.13
- psr/simple-cache: ^1.0 || ^2.0
- zircote/swagger-php: ^4.2.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.17 || ^3.0
- nyholm/psr7: ^1.4
- nyholm/psr7-server: ^1.0
- phpunit/phpunit: >=8.0
- symfony/cache: ^5.0 || ^6.0
- symfony/psr-http-message-bridge: ^2.1
Suggests
- radebatz/openapi-verifier: Allows your PHPUnit tests to validate your controller response against the OpenAPI annotations.
This package is auto-updated.
Last update: 2024-09-30 17:57:54 UTC
README
Introduction
Allows to (re-)use Swagger-PHP annotations to configure routes in the following frameworks:
Requirements
- PHP 7.2 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 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'); } }
Documentation
License
The openapi-router project is released under the MIT license.