⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix: make the OpenAPI artifact and its check environment independent
Andrej Acevski927552ffb327
diff --git a/apps/api/scripts/export-openapi.ts b/apps/api/scripts/export-openapi.tsindex 71bfe929e..00ae471ca 100644--- a/apps/api/scripts/export-openapi.ts+++ b/apps/api/scripts/export-openapi.ts@@ -9,8 +9,11 @@ if (!response.ok) {throw new Error(`OpenAPI export failed with status ${response.status}`);}-const spec = await response.json();-// Defaults to the file the docs site reads; the drift check passes a temp path.+const spec = (await response.json()) as { servers?: unknown };++spec.servers = [+ { url: "https://cloud.kaneo.app/api", description: "Kaneo API Server" },+];const outputPath = process.argv[2]? resolve(process.argv[2]): resolve(import.meta.dirname, "../../docs/openapi.json");diff --git a/scripts/openapi/check.mjs b/scripts/openapi/check.mjsindex 0de637cd6..bdc8d6630 100644--- a/scripts/openapi/check.mjs+++ b/scripts/openapi/check.mjs@@ -1,26 +1,24 @@#!/usr/bin/env node-// apps/docs/openapi.json is a committed artifact that Mintlify serves as the API-// reference, so it only stays truthful if something regenerates it. This fails-// when the committed document no longer matches what the routes produce.import { execFileSync } from "node:child_process";-import { copyFileSync, mkdtempSync, readFileSync, rmSync } from "node:fs";+import {+ copyFileSync,+ existsSync,+ mkdtempSync,+ readFileSync,+ rmSync,+} from "node:fs";import { tmpdir } from "node:os";import { join, resolve } from "node:path";const COMMITTED = resolve("apps/docs/openapi.json");const FIX = process.argv.includes("--fix");+const RUN = {+ stdio: ["ignore", "ignore", "inherit"],+ shell: process.platform === "win32",+};-const workdir = mkdtempSync(join(tmpdir(), "kaneo-openapi-"));-const generated = join(workdir, "openapi.json");--try {- // The exporter imports the API, which imports workspace packages from their- // built dist output, so those builds have to run first. Every other turbo- // task gets this from dependsOn: ["^build"]; this one is invoked directly.- execFileSync("pnpm", ["turbo", "build", "--filter=@kaneo/api^..."], {- stdio: ["ignore", "ignore", "inherit"],- });-+function generate(into) {+ execFileSync("pnpm", ["turbo", "build", "--filter=@kaneo/api^..."], RUN);execFileSync("pnpm",[@@ -29,29 +27,43 @@ try {"exec","tsx","scripts/export-openapi.ts",- generated,+ into,],- { stdio: ["ignore", "ignore", "inherit"] },+ RUN,);+}- if (readFileSync(COMMITTED, "utf8") === readFileSync(generated, "utf8")) {- console.log("apps/docs/openapi.json is up to date");- process.exit(0);- }+function run() {+ const workdir = mkdtempSync(join(tmpdir(), "kaneo-openapi-"));+ const generated = join(workdir, "openapi.json");- if (FIX) {- copyFileSync(generated, COMMITTED);- console.log("apps/docs/openapi.json regenerated");- process.exit(0);- }+ try {+ generate(generated);- console.error(- "apps/docs/openapi.json is out of date with the API routes.\n" +- "The docs site serves this file, so it has to be regenerated and committed\n" +- "whenever a route, request schema, or response schema changes.\n\n" +- " pnpm openapi:check:fix\n",- );- process.exit(1);-} finally {- rmSync(workdir, { recursive: true, force: true });+ const committed = existsSync(COMMITTED)+ ? readFileSync(COMMITTED, "utf8")+ : null;+ if (committed === readFileSync(generated, "utf8")) {+ console.log("apps/docs/openapi.json is up to date");+ return 0;+ }++ if (FIX) {+ copyFileSync(generated, COMMITTED);+ console.log("apps/docs/openapi.json regenerated");+ return 0;+ }++ console.error(+ `apps/docs/openapi.json is ${committed === null ? "missing" : "out of date"}.\n` ++ "The docs site serves this file, so it has to be regenerated and committed\n" ++ "whenever a route, request schema, or response schema changes.\n\n" ++ " pnpm openapi:check:fix\n",+ );+ return 1;+ } finally {+ rmSync(workdir, { recursive: true, force: true });+ }}++process.exitCode = run();