|
| 1 | +#!/usr/bin/env tsx |
| 2 | + |
| 3 | +/** |
| 4 | + * Script to generate OpenAPI specification locally |
| 5 | + * This runs in CI/CD to generate the openapi.json file |
| 6 | + * which can then be consumed by the documentation website |
| 7 | + */ |
| 8 | + |
| 9 | +import { writeFileSync } from "node:fs"; |
| 10 | +import { dirname, resolve } from "node:path"; |
| 11 | +import { fileURLToPath } from "node:url"; |
| 12 | +import { generateOpenApiDocument } from "@dokploy/trpc-openapi"; |
| 13 | +import { appRouter } from "../server/api/root"; |
| 14 | + |
| 15 | +const __filename = fileURLToPath(import.meta.url); |
| 16 | +const __dirname = dirname(__filename); |
| 17 | + |
| 18 | +async function generateOpenAPI() { |
| 19 | + try { |
| 20 | + console.log("🔄 Generating OpenAPI specification..."); |
| 21 | + |
| 22 | + const openApiDocument = generateOpenApiDocument(appRouter, { |
| 23 | + title: "Dokploy API", |
| 24 | + version: "1.0.0", |
| 25 | + baseUrl: "https://your-dokploy-instance.com/api", |
| 26 | + docsUrl: "https://docs.dokploy.com/api", |
| 27 | + tags: [ |
| 28 | + "admin", |
| 29 | + "docker", |
| 30 | + "compose", |
| 31 | + "registry", |
| 32 | + "cluster", |
| 33 | + "user", |
| 34 | + "domain", |
| 35 | + "destination", |
| 36 | + "backup", |
| 37 | + "deployment", |
| 38 | + "mounts", |
| 39 | + "certificates", |
| 40 | + "settings", |
| 41 | + "security", |
| 42 | + "redirects", |
| 43 | + "port", |
| 44 | + "project", |
| 45 | + "application", |
| 46 | + "mysql", |
| 47 | + "postgres", |
| 48 | + "redis", |
| 49 | + "mongo", |
| 50 | + "mariadb", |
| 51 | + "sshRouter", |
| 52 | + "gitProvider", |
| 53 | + "bitbucket", |
| 54 | + "github", |
| 55 | + "gitlab", |
| 56 | + "gitea", |
| 57 | + "server", |
| 58 | + "swarm", |
| 59 | + "ai", |
| 60 | + "organization", |
| 61 | + "schedule", |
| 62 | + "rollback", |
| 63 | + "volumeBackups", |
| 64 | + "environment", |
| 65 | + ], |
| 66 | + }); |
| 67 | + |
| 68 | + // Enhance metadata |
| 69 | + openApiDocument.info = { |
| 70 | + title: "Dokploy API", |
| 71 | + description: |
| 72 | + "Complete API documentation for Dokploy - Deploy applications, manage databases, and orchestrate your infrastructure. This API allows you to programmatically manage all aspects of your Dokploy instance.", |
| 73 | + version: "1.0.0", |
| 74 | + contact: { |
| 75 | + name: "Dokploy Team", |
| 76 | + url: "https://dokploy.com", |
| 77 | + }, |
| 78 | + license: { |
| 79 | + name: "Apache 2.0", |
| 80 | + url: "https://github.com/dokploy/dokploy/blob/canary/LICENSE", |
| 81 | + }, |
| 82 | + }; |
| 83 | + |
| 84 | + // Add security schemes |
| 85 | + openApiDocument.components = { |
| 86 | + ...openApiDocument.components, |
| 87 | + securitySchemes: { |
| 88 | + apiKey: { |
| 89 | + type: "apiKey", |
| 90 | + in: "header", |
| 91 | + name: "x-api-key", |
| 92 | + description: |
| 93 | + "API key authentication. Generate an API key from your Dokploy dashboard under Settings > API Keys.", |
| 94 | + }, |
| 95 | + }, |
| 96 | + }; |
| 97 | + |
| 98 | + // Apply global security |
| 99 | + openApiDocument.security = [ |
| 100 | + { |
| 101 | + apiKey: [], |
| 102 | + }, |
| 103 | + ]; |
| 104 | + |
| 105 | + // Add external docs |
| 106 | + openApiDocument.externalDocs = { |
| 107 | + description: "Full documentation", |
| 108 | + url: "https://docs.dokploy.com", |
| 109 | + }; |
| 110 | + |
| 111 | + // Write to root of repo |
| 112 | + const outputPath = resolve(__dirname, "../../../openapi.json"); |
| 113 | + writeFileSync( |
| 114 | + outputPath, |
| 115 | + JSON.stringify(openApiDocument, null, 2), |
| 116 | + "utf-8", |
| 117 | + ); |
| 118 | + |
| 119 | + console.log("✅ OpenAPI specification generated successfully!"); |
| 120 | + console.log(`📄 Output: ${outputPath}`); |
| 121 | + console.log( |
| 122 | + `📊 Endpoints: ${Object.keys(openApiDocument.paths || {}).length}`, |
| 123 | + ); |
| 124 | + } catch (error) { |
| 125 | + console.error("❌ Error generating OpenAPI specification:", error); |
| 126 | + process.exit(1); |
| 127 | + } finally { |
| 128 | + process.exit(0); |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +generateOpenAPI(); |
0 commit comments