PHP code example of radebatz / openapi-router

1. Go to this page and download the library: Download radebatz/openapi-router 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/ */

    

radebatz / openapi-router example snippets




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');
    }
}



use Radebatz\OpenApi\Routing\Adapters\SlimRoutingAdapter;
use Radebatz\OpenApi\Routing\OpenApiRouter;
use Slim\App;

s();

$app->run();