-
Notifications
You must be signed in to change notification settings - Fork 96
/
generate-opeapi-types.ts
executable file
·38 lines (31 loc) · 1.23 KB
/
generate-opeapi-types.ts
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
38
#!/usr/bin/env -S deno run --allow-net --allow-write=./src/generated-types --allow-read=./src/generated-types --allow-read=. --no-prompt --allow-env --unstable-unsafe-proto
import { emptyDirSync } from "jsr:@std/fs"
import { convert } from "https://esm.sh/gh/APIs-guru/google-discovery-to-swagger@openapi3/src/index.js?bundle&dev&a.js"
import openapiTS, { astToString } from "https://esm.sh/[email protected]?bundle"
const data = await fetch(
"https://github.com/google/generative-ai-go/raw/main/genai/internal/generativelanguage/v1beta/generativelanguage-api.json",
)
const openapi = convert((await data.json()) ?? "{}")
const openapis = [
{
data: await fetch("https://raw.githubusercontent.com/openai/openai-openapi/refs/heads/master/openapi.yaml").then(
(res) => res.text(),
),
path: "./src/generated-types/openai-types.ts",
},
{
path: "./src/generated-types/gemini-types.ts",
data: openapi,
},
] as const
emptyDirSync("./src/generated-types/")
for (const { path, data } of openapis) {
const ast = await openapiTS(data, {
excludeDeprecated: false,
cwd: "",
alphabetize: true,
additionalProperties: true,
})
const code = astToString(ast)
await Deno.writeTextFile(path, code)
}