Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
4.0 kB ยท 143 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144import { readFileSync, writeFileSync } from "node:fs";import { dirname, join } from "node:path";
// oxlint-disable-next-line typescript/no-non-null-assertionconst OPENAPI_PATH = join(dirname(import.meta.dirname!), "gen", "openapi.yaml");
const CONNECT_PARAMS = new Set([ "Connect-Protocol-Version", "Connect-Timeout-Ms", "encoding", "base64", "compression", "connect",]);
const CONNECT_SCHEMAS = new Set([ "connect-protocol-version", "connect-timeout-header", "encoding", "base64", "compression", "connect",]);
const lines = readFileSync(OPENAPI_PATH, "utf-8").split("\n");const out: string[] = [];
let i = 0;while (i < lines.length) { const line = lines[i];
// Remove Connect-specific parameter blocks if (/^\s+- name:\s/.test(line)) { const nameMatch = line.match(/- name:\s+(.+)/); if (nameMatch && CONNECT_PARAMS.has(nameMatch[1].trim())) { const baseIndent = line.search(/\S/); i++; while (i < lines.length) { const nextLine = lines[i]; if (nextLine.trim() === "") { i++; continue; } const nextIndent = nextLine.search(/\S/); if (nextIndent > baseIndent) { i++; continue; } break; } continue; } }
// Remove Connect-specific schema definitions from components.schemas if (/^ {4}\S/.test(line) && line.trim().endsWith(":")) { const schemaName = line.trim().replace(/:$/, ""); if (CONNECT_SCHEMAS.has(schemaName)) { const baseIndent = line.search(/\S/); i++; while (i < lines.length) { const nextLine = lines[i]; if (nextLine.trim() === "") { i++; continue; } const nextIndent = nextLine.search(/\S/); if (nextIndent > baseIndent) { i++; continue; } break; } continue; } }
out.push(line); i++;}
// Second pass: remove empty "parameters:" keys left after stripping all paramsconst final: string[] = [];for (let j = 0; j < out.length; j++) { if (/^\s+parameters:\s*$/.test(out[j])) { let k = j + 1; while (k < out.length && out[k].trim() === "") k++; if (k < out.length && /^\s+- name:/.test(out[k])) { final.push(out[j]); } continue; } final.push(out[j]);}
// Every operation runs behind the rate limiter; the generator only emits per-RPC responses.// The shared response lives here rather than in base.openapi.yaml because the plugin// validates the base file before merging, so it cannot reference the generated connect.error schema.const RATE_LIMITED_COMPONENT = [ " responses:", " RateLimited:", " description: Rate limit exceeded (Connect code resource_exhausted). Retry after the number of seconds in the Retry-After header. See https://www.openstatus.dev/docs/reference/api-rate-limits.", " headers:", " Retry-After:", " description: Seconds to wait before retrying.", " schema:", " type: integer", " example: 7", " content:", " application/json:", " schema:", " $ref: '#/components/schemas/connect.error'",];const RATE_LIMITED_REF = [ ' "429":', " $ref: '#/components/responses/RateLimited'",];const withRateLimit: string[] = [];for (const line of final) { if (/^components:\s*$/.test(line)) { withRateLimit.push(line, ...RATE_LIMITED_COMPONENT); continue; } withRateLimit.push(line); if (/^ responses:\s*$/.test(line)) withRateLimit.push(...RATE_LIMITED_REF);}
const cleaned = withRateLimit.join("\n");writeFileSync(OPENAPI_PATH, cleaned);
// Copy cleaned spec to server static directoryconst serverOpenAPIPath = join( // oxlint-disable-next-line typescript/no-non-null-assertion dirname(import.meta.dirname!), "..", "..", "apps", "server", "static", "openapi.yaml",);writeFileSync(serverOpenAPIPath, cleaned);