You've already forked Php-Template
All checks were successful
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 4m0s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 4m11s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 4m22s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 4m42s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 4m27s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 2m55s
35 lines
939 B
PHP
35 lines
939 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Siteworxpro\App\Controllers;
|
|
|
|
use Nyholm\Psr7\Response;
|
|
use Nyholm\Psr7\ServerRequest;
|
|
use OpenApi\Generator;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
class SwaggerController extends Controller
|
|
{
|
|
public function get(ServerRequest $request): ResponseInterface
|
|
{
|
|
$openapi = new Generator()->generate([
|
|
__DIR__ . '/../Controllers',
|
|
__DIR__ . '/../Models',
|
|
]);
|
|
|
|
$response = new Response();
|
|
|
|
if (
|
|
$request->getHeaderLine('Accept') === 'application/json' ||
|
|
str_contains($request->getUri()->getPath(), '.json')
|
|
) {
|
|
$response->getBody()->write($openapi->toJson());
|
|
return $response->withHeader('Content-Type', 'application/json');
|
|
}
|
|
|
|
$response->getBody()->write($openapi->toYaml());
|
|
return $response->withHeader('Content-Type', 'application/x-yaml');
|
|
}
|
|
}
|