1. Go to this page and download the library: Download sunrise/http-router-openapi 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/ */
sunrise / http-router-openapi example snippets
use Psr\SimpleCache\CacheInterface;
use Sunrise\Http\Router\OpenApi\Object\Info;
use Sunrise\Http\Router\OpenApi\OpenApi;
use Sunrise\Http\Router\OpenApi\RouteInterface;
$openapi = new OpenApi(new Info('Acme', '1.0.0'));
// Passing PSR-16 cache to the openapi object:
/** @var CacheInterface $cache */
$openapi->setCache($cache);
// Passing all routes to the openapi object:
/** @var RouteInterface[] $routes */
$openapi->addRoute(...$routes);
// When using Sunrise Router:
/** @var \Sunrise\Http\Router\Router $router */
$openapi->addRoute(...$router->getRoutes());
// Converting the openapi object to JSON document:
$openapi->toJson();
// Converting the openapi object to YAML document:
$openapi->toYaml();
// Converting the openapi object to an array:
$openapi->toArray();
use Sunrise\Http\Router\OpenApi\Middleware\RequestValidationMiddleware;
use Sunrise\Http\Router\OpenApi\OpenApi;
/** @var OpenApi $openapi */
$middleware = new RequestValidationMiddleware($openapi);
use Sunrise\Http\Router\OpenApi\Command\GenerateOpenapiDocumentCommand;
use Sunrise\Http\Router\OpenApi\OpenApi;
/** @var OpenApi $openapi */
$command = new GenerateOpenapiDocumentCommand($openapi);
use Sunrise\Http\Router\OpenApi\Command\GenerateJsonSchemaCommand;
use Sunrise\Http\Router\OpenApi\OpenApi;
/** @var OpenApi $openapi */
$command = new GenerateJsonSchemaCommand($openapi);
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
use Sunrise\Http\Router\OpenApi\Test\OpenapiTestKit;
class SomeTest extends TestCase
{
use OpenapiTestKit;
public function testResponseBodyMatchesDescription() : void
{
// some logic to run a route...
/** @var ResponseInterface $response */
$this->assertResponseBodyMatchesDescription('route.name', $response);
}
}