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