You've already forked Php-Template
feat: add Swagger UI service to docker-compose and update OpenAPI annotations in controllers
Some checks failed
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Failing after 2m49s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 2m42s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 2m50s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 2m44s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 3m5s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 2m54s
Some checks failed
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Failing after 2m49s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 2m42s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 2m50s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 2m44s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 3m5s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 2m54s
This commit is contained in:
40
src/Controllers/OpenApiController.php
Normal file
40
src/Controllers/OpenApiController.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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 OpenApiController extends Controller
|
||||
{
|
||||
/**
|
||||
* Handles the GET request to generate and return the OpenAPI specification.
|
||||
*
|
||||
* @param ServerRequest $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user