Files
HealthLog/scripts/check-openapi.ts
T
Marc-André Bombeck 17b8d8d2c2 chore(release): v1.4.25
Largest feature delta in the v1.4.x line. Insights expands into seven dedicated metric sub-pages; GLP-1 medication tracking lands end-to-end (drug-level chart with Research Mode acknowledgment, EMA titration ladder, cadence + compliance, side-effect taxonomy, pen/vial inventory); cross-source priority becomes a two-axis resolver; per-user timezone threads through ten analytics surfaces; Withings activity + sleep v2 sync; onboarding rebuilt as a nested-route wizard; Personal Records ship end-to-end; Health Score provenance accordion; Coach runs native first-party prompts across six locales with a 1800-assertion refusal-probe matrix; OpenAPI drift gate hard-fails; multi-arch GHCR image. Migrations 0043 through 0060 are additive and forward-only. PROMPT_VERSION 4.24.0 → 4.25.0 with GROUND RULE 9 (refuses dose recommendations) and GROUND RULE 15 (refuses drug-level estimates with MDR + MDCG 2021-24 cites).

See CHANGELOG.md for the full per-section delta.
2026-05-14 23:49:32 +02:00

59 lines
2.0 KiB
TypeScript

#!/usr/bin/env tsx
/**
* Compare the freshly-generated OpenAPI spec against the committed
* `docs/api/openapi.yaml`. Exits non-zero on drift.
*
* Used by the CI gate in `.github/workflows/security.yml`. Hard-fails on
* drift since v1.4.25 — the Zod registry is the source of truth for the
* public API contract that the v1.5 iOS Swift codegen consumes.
*/
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { stringify } from "yaml";
import { buildOpenApiDocument } from "../src/lib/openapi/registry";
const SPEC_PATH = resolve(__dirname, "..", "docs", "api", "openapi.yaml");
function main(): void {
const document = buildOpenApiDocument();
const generated = stringify(document, {
sortMapEntries: true,
lineWidth: 120,
});
const committed = readFileSync(SPEC_PATH, "utf8");
if (generated === committed) {
console.log("OpenAPI spec in sync with source schemas.");
return;
}
console.error(
"OpenAPI spec drift detected. Run `pnpm openapi:generate` and commit the result.",
);
// Surface a unified-diff-ish hint so PR reviewers see what changed
// without having to re-run the generator locally.
const genLines = generated.split("\n");
const onDiskLines = committed.split("\n");
const max = Math.max(genLines.length, onDiskLines.length);
for (let i = 0; i < max; i++) {
if (genLines[i] !== onDiskLines[i]) {
console.error(
`Line ${i + 1}:\n generated: ${JSON.stringify(genLines[i] ?? "")}\n committed: ${JSON.stringify(onDiskLines[i] ?? "")}`,
);
// Limit the noise — first 5 mismatched lines is enough to point
// the maintainer at the regenerate command.
let shown = 1;
for (let j = i + 1; j < max && shown < 5; j++) {
if (genLines[j] !== onDiskLines[j]) {
console.error(
`Line ${j + 1}:\n generated: ${JSON.stringify(genLines[j] ?? "")}\n committed: ${JSON.stringify(onDiskLines[j] ?? "")}`,
);
shown++;
}
}
break;
}
}
process.exit(1);
}
main();