-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathgenerate-openapi.ts
More file actions
37 lines (32 loc) · 1.17 KB
/
generate-openapi.ts
File metadata and controls
37 lines (32 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* Generates the OpenAPI specification JSON for ENSApi.
*
* This script can run without any environment variables or config because it
* imports only from the lightweight `.routes.ts` description files via
* `createRoutesForSpec()`, which have zero config dependencies.
*
* The version is resolved from (in order of precedence):
* 1. OPENAPI_VERSION_OVERRIDE env var
* 2. package.json version
* 3. openapiDocumentation.info.version (placeholder fallback)
*
* Usage:
* pnpm generate:openapi > openapi.json
* pnpm generate:openapi # prints to stdout
* OPENAPI_VERSION_OVERRIDE=1.2.3 pnpm generate:openapi
*/
import packageJson from "@/../package.json" with { type: "json" };
import { openapiDocumentation } from "@/openapi";
import { createRoutesForSpec } from "@/openapi-routes";
const version =
process.env.OPENAPI_VERSION_OVERRIDE || packageJson.version || openapiDocumentation.info.version;
const app = createRoutesForSpec();
const spec = app.getOpenAPI31Document({
...openapiDocumentation,
info: {
...openapiDocumentation.info,
version,
},
});
process.stdout.write(JSON.stringify(spec, null, 2));
process.stdout.write("\n");