Files
MediaCollectorLibary/routes/api-docs.php
Lars Behrends b728b0c72d Enhance API functionality and improve JWT authentication
- Added JWT authentication support in AuthService and JwtService.
- Implemented token generation and refresh mechanisms.
- Updated ApiAuthMiddleware to handle authentication for protected routes.
- Created ApiController and BaseApiController for standardized API responses.
- Developed MediaController for managing media items with pagination and search capabilities.
- Introduced DocsController for serving API documentation via Swagger UI.
- Added routes for API documentation and media management.
- Improved error handling and response formatting across API endpoints.
- Updated composer.json to include necessary JWT and Swagger UI dependencies.
2025-12-31 10:08:49 +01:00

43 lines
1.4 KiB
PHP

<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Routing\RouteCollectorProxy;
use App\Controllers\Api\DocsController;
// Documentation routes
$app->group('/docs', function (RouteCollectorProxy $group) {
$docsController = $this->get(DocsController::class);
// Documentation UI
$group->get('/api', [$docsController, 'showDocs']);
// OpenAPI JSON specification
$group->get('/api-docs.json', [$docsController, 'getOpenApiSpec']);
// Serve Swagger UI assets
$group->get('/swagger-ui/{file:.+}', function (Request $request, Response $response, array $args) {
$file = $args['file'];
$swaggerUiPath = __DIR__ . '/../../vendor/swagger-api/swagger-ui/dist';
$filePath = $swaggerUiPath . '/' . $file;
if (!file_exists($filePath)) {
return $response->withStatus(404, 'File not found');
}
$extension = pathinfo($file, PATHINFO_EXTENSION);
$contentTypes = [
'css' => 'text/css',
'js' => 'application/javascript',
'png' => 'image/png',
'json' => 'application/json',
'html' => 'text/html',
];
$contentType = $contentTypes[$extension] ?? 'text/plain';
$response->getBody()->write(file_get_contents($filePath));
return $response->withHeader('Content-Type', $contentType);
});
});