|
1 | 1 | #!/usr/bin/env -S deno run --allow-net --allow-write=./src/generated-types --allow-read=./src/generated-types --allow-read=. --no-prompt --allow-env |
2 | 2 | import { emptyDirSync } from "jsr:@std/fs" |
| 3 | +import { parse as parseYaml } from "jsr:@std/yaml" |
3 | 4 | import openapiTS, { astToString } from "https://esm.sh/openapi-typescript@7.5.2?bundle" |
4 | 5 |
|
| 6 | +// @ts-types="https://unpkg.com/openapi-format@1.25.0/types/openapi-format.d.ts" |
| 7 | +import { openapiFilter } from "openapi-format" |
| 8 | + |
5 | 9 | const openapis = [ |
6 | 10 | { |
7 | | - data: await fetch("https://raw.githubusercontent.com/openai/openai-openapi/refs/heads/master/openapi.yaml").then( |
8 | | - (res) => res.text(), |
9 | | - ), |
| 11 | + data: await fetch("https://raw.githubusercontent.com/openai/openai-openapi/refs/heads/master/openapi.yaml") |
| 12 | + .then((res) => res.text()) |
| 13 | + .then(parseYaml), |
10 | 14 | path: "./src/generated-types/openai-types.ts", |
11 | 15 | }, |
12 | 16 | { |
13 | 17 | data: await fetch( |
14 | 18 | "https://github.com/zuisong/googleapis-openapi/raw/refs/heads/main/googleapis/generativelanguage/v1alpha/generativelanguage-api-openapi_v3.json", |
15 | | - ).then((res) => res.text()), |
| 19 | + ) |
| 20 | + .then((res) => res.text()) |
| 21 | + .then(JSON.parse), |
16 | 22 | path: "./src/generated-types/gemini-types.ts", |
17 | 23 | }, |
18 | 24 | ] as const |
19 | 25 |
|
20 | 26 | emptyDirSync("./src/generated-types/") |
21 | 27 |
|
22 | 28 | for (const { path, data } of openapis) { |
23 | | - const ast = await openapiTS(data, { |
| 29 | + const { data: res } = await openapiFilter(data, { |
| 30 | + filterSet: { |
| 31 | + inverseOperationIds: [ |
| 32 | + /// openai |
| 33 | + "createChatCompletion", |
| 34 | + "createEmbedding", |
| 35 | + "listModels", |
| 36 | + /// googleapis |
| 37 | + "generativelanguage.tunedModels.streamGenerateContent", |
| 38 | + "generativelanguage.models.embedContent", |
| 39 | + "generativelanguage.tunedModels.create", |
| 40 | + ], |
| 41 | + unusedComponents: ["schemas"], |
| 42 | + preserveEmptyObjects: false, |
| 43 | + }, |
| 44 | + defaultFilter: {}, |
| 45 | + }) |
| 46 | + |
| 47 | + const ast = await openapiTS(res, { |
24 | 48 | excludeDeprecated: false, |
25 | 49 | cwd: "", |
26 | 50 | alphabetize: true, |
|
0 commit comments