diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-07-06 23:01:14 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2025-07-06 23:01:14 +0000 |
| commit | 71458166108ab805e8924f851953489f0c00d989 (patch) | |
| tree | a1da0708db17861d2e3e07637e6427779ef43e50 | |
| parent | 0eeefd686f2d44f63ba7a97f17c8db1341d0d83b (diff) | |
| download | karakeep-71458166108ab805e8924f851953489f0c00d989.tar.zst | |
build: Add an open-api husky check
| -rw-r--r-- | .husky/pre-commit | 1 | ||||
| -rw-r--r-- | packages/open-api/index.ts | 18 | ||||
| -rw-r--r-- | packages/open-api/package.json | 1 |
3 files changed, 19 insertions, 1 deletions
diff --git a/.husky/pre-commit b/.husky/pre-commit index 5a448e3b..eb3cb0a2 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -2,3 +2,4 @@ pnpm typecheck pnpm format --check pnpm lint pnpm exec sherif +pnpm run --filter @karakeep/open-api check diff --git a/packages/open-api/index.ts b/packages/open-api/index.ts index 06fbc913..057a823f 100644 --- a/packages/open-api/index.ts +++ b/packages/open-api/index.ts @@ -1,4 +1,5 @@ import * as fs from "fs"; +import * as process from "process"; import { OpenApiGeneratorV3, OpenAPIRegistry, @@ -54,4 +55,19 @@ function writeDocumentation() { }); } -writeDocumentation(); +function checkDocumentation() { + const docs = getOpenApiDocumentation(); + const fileContent = JSON.stringify(docs, null, 2); + const oldContent = fs.readFileSync(`./karakeep-openapi-spec.json`, { + encoding: "utf-8", + }); + if (oldContent !== fileContent) { + process.exit(1); + } +} + +if (process.argv[2] === "check") { + checkDocumentation(); +} else { + writeDocumentation(); +} diff --git a/packages/open-api/package.json b/packages/open-api/package.json index d88543a9..a2a20ef7 100644 --- a/packages/open-api/package.json +++ b/packages/open-api/package.json @@ -16,6 +16,7 @@ }, "scripts": { "typecheck": "tsc --noEmit", + "check": "tsx index.ts check", "generate": "tsx index.ts", "format": "prettier . --ignore-path ../../.prettierignore", "format:fix": "prettier . --write --ignore-path ../../.prettierignore", |
