Skip to content

Commit b98a970

Browse files
committed
add generate openapi script
1 parent ef7ab2a commit b98a970

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

docs/docs.ensnode.io/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"homepage": "https://github.com/namehash/ensnode/tree/main/docs/docs.ensnode.io",
1414
"scripts": {
1515
"mint": "pnpm dlx mint@^4.1.0",
16-
"generate:openapi": "pnpm --filter ensapi exec tsx --tsconfig tsconfig.json ../../scripts/generate-ensapi-openapi.ts"
16+
"generate:openapi": "pnpm --filter ensapi exec tsx --tsconfig tsconfig.json ../../scripts/generate-openapi.ts --out ../../docs/docs.ensnode.io/ensapi-openapi.json"
1717
},
1818
"packageManager": "pnpm@10.28.0"
1919
}
Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
/**
2-
* Generates a static OpenAPI 3.1 JSON document for ENSApi.
2+
* Generates a static OpenAPI 3.1 JSON document for an app.
33
*
4-
* Usage: pnpm generate:openapi
4+
* This script is app-agnostic — it imports `generateOpenApi31Document` from
5+
* `@/openapi-document`, which resolves to whichever app context the script
6+
* is executed in (controlled by `--filter <app>` in the calling script).
57
*
6-
* Output: docs/docs.ensnode.io/ensapi-openapi.json
8+
* Usage:
9+
* pnpm --filter <app> exec tsx --tsconfig tsconfig.json \
10+
* ../../scripts/generate-openapi.ts --out <output-path>
11+
*
12+
* Example:
13+
* pnpm --filter ensapi exec tsx --tsconfig tsconfig.json \
14+
* ../../scripts/generate-openapi.ts --out ../../docs/docs.ensnode.io/ensapi-openapi.json
15+
*
16+
* The --out path is resolved relative to the app's root directory.
717
*
818
* This script has no runtime dependencies — it calls generateOpenApi31Document()
919
* which uses only stub route handlers and static metadata.
@@ -12,12 +22,23 @@
1222
import { execFileSync } from "node:child_process";
1323
import { mkdirSync, writeFileSync } from "node:fs";
1424
import { dirname, resolve } from "node:path";
15-
import { fileURLToPath } from "node:url";
25+
import { parseArgs } from "node:util";
1626

1727
import { generateOpenApi31Document } from "@/openapi-document";
1828

19-
const __dirname = dirname(fileURLToPath(import.meta.url));
20-
const outputPath = resolve(__dirname, "..", "docs", "docs.ensnode.io", "ensapi-openapi.json");
29+
const { values } = parseArgs({
30+
options: {
31+
out: { type: "string" },
32+
},
33+
strict: true,
34+
});
35+
36+
if (!values.out) {
37+
console.error("Error: --out <path> is required.");
38+
process.exit(1);
39+
}
40+
41+
const outputPath = resolve(values.out);
2142

2243
// Generate the document (no additional servers for the static spec)
2344
const document = generateOpenApi31Document();

0 commit comments

Comments
 (0)