Files
Termix/src/backend/swagger.ts
T

158 lines
3.9 KiB
TypeScript
Raw Normal View History

2026-06-04 15:16:53 -04:00
import swaggerJSDoc from "@deadendjs/swagger-jsdoc";
2026-05-28 22:29:20 -05:00
import path from "path";
import { fileURLToPath } from "url";
import { promises as fs } from "fs";
import { systemLogger } from "./utils/logger.js";
2026-06-04 15:16:53 -04:00
type SwaggerJSDocOptions = Parameters<typeof swaggerJSDoc>[0];
2026-05-28 22:29:20 -05:00
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
2026-06-04 15:16:53 -04:00
const swaggerOptions: SwaggerJSDocOptions = {
2026-05-28 22:29:20 -05:00
definition: {
openapi: "3.0.3",
info: {
title: "Termix API",
version: "0.0.0",
description: "Termix Backend API Reference",
},
servers: [
{
url: "http://localhost:30001",
description: "Main database and authentication server",
},
{
url: "http://localhost:30003",
description: "SSH tunnel management server",
},
{
url: "http://localhost:30004",
description: "SSH file manager server",
},
{
url: "http://localhost:30005",
description: "Server statistics and monitoring server",
},
{
url: "http://localhost:30006",
description: "Dashboard server",
},
{
url: "http://localhost:30007",
description: "Docker management server",
},
],
components: {
securitySchemes: {
bearerAuth: {
type: "http",
scheme: "bearer",
bearerFormat: "JWT",
},
},
schemas: {
Error: {
type: "object",
properties: {
error: { type: "string" },
details: { type: "string" },
},
},
},
},
security: [
{
bearerAuth: [],
},
],
tags: [
{
name: "Alerts",
description: "System alerts and notifications management",
},
{
name: "Credentials",
description: "SSH credential management",
},
{
name: "Network Topology",
description: "Network topology visualization and management",
},
{
name: "RBAC",
description: "Role-based access control for host sharing",
},
{
name: "Snippets",
description: "Command snippet management",
},
{
name: "Terminal",
description: "Terminal command history",
},
{
name: "Users",
description: "User management and authentication",
},
{
name: "Dashboard",
description: "Dashboard statistics and activity",
},
{
name: "Docker",
description: "Docker container management",
},
{
name: "SSH Tunnels",
description: "SSH tunnel connection management",
},
{
name: "Server Stats",
description: "Server status monitoring and metrics collection",
},
{
name: "File Manager",
description: "SSH file management operations",
},
],
},
apis: [
path.join(__dirname, "database", "routes", "*.js").replace(/\\/g, "/"),
path.join(__dirname, "dashboard.js").replace(/\\/g, "/"),
path.join(__dirname, "ssh", "*.js").replace(/\\/g, "/"),
path.join(__dirname, "guacamole", "routes.js").replace(/\\/g, "/"),
],
};
async function generateOpenAPISpec() {
try {
systemLogger.info("Generating OpenAPI specification", {
operation: "openapi_generate_start",
});
2026-06-04 15:16:53 -04:00
const swaggerSpec = await swaggerJSDoc(swaggerOptions);
2026-05-28 22:29:20 -05:00
const outputPath = path.join(__dirname, "..", "..", "..", "openapi.json");
await fs.writeFile(
outputPath,
JSON.stringify(swaggerSpec, null, 2),
"utf-8",
);
systemLogger.success("OpenAPI specification generated", {
operation: "openapi_generate_success",
});
} catch (error) {
systemLogger.error("Failed to generate OpenAPI specification", error, {
operation: "openapi_generation",
});
process.exit(1);
}
}
generateOpenAPISpec();
export { swaggerOptions, generateOpenAPISpec };