Skip to content

Commit

Permalink
chore!: remove unused typescript types
Browse files Browse the repository at this point in the history
  • Loading branch information
zuisong committed Feb 20, 2025
1 parent 37aa39b commit 3de240b
Show file tree
Hide file tree
Showing 6 changed files with 2,002 additions and 16,525 deletions.
3 changes: 3 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"lock": {
"frozen": false
},
"imports": {
"openapi-format": "https://esm.sh/openapi-format?bundle"
},
"nodeModulesDir": "auto",
"fmt": {
"exclude": ["*"]
Expand Down
7 changes: 7 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 29 additions & 5 deletions generate-opeapi-types.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,50 @@
#!/usr/bin/env -S deno run --allow-net --allow-write=./src/generated-types --allow-read=./src/generated-types --allow-read=. --no-prompt --allow-env
import { emptyDirSync } from "jsr:@std/fs"
import { parse as parseYaml } from "jsr:@std/yaml"
import openapiTS, { astToString } from "https://esm.sh/[email protected]?bundle"

// @ts-types="https://unpkg.com/[email protected]/types/openapi-format.d.ts"
import { openapiFilter } from "openapi-format"

const openapis = [
{
data: await fetch("https://raw.githubusercontent.com/openai/openai-openapi/refs/heads/master/openapi.yaml").then(
(res) => res.text(),
),
data: await fetch("https://raw.githubusercontent.com/openai/openai-openapi/refs/heads/master/openapi.yaml")
.then((res) => res.text())
.then(parseYaml),
path: "./src/generated-types/openai-types.ts",
},
{
data: await fetch(
"https://github.com/zuisong/googleapis-openapi/raw/refs/heads/main/googleapis/generativelanguage/v1alpha/generativelanguage-api-openapi_v3.json",
).then((res) => res.text()),
)
.then((res) => res.text())
.then(JSON.parse),
path: "./src/generated-types/gemini-types.ts",
},
] as const

emptyDirSync("./src/generated-types/")

for (const { path, data } of openapis) {
const ast = await openapiTS(data, {
const { data: res } = await openapiFilter(data, {
filterSet: {
inverseOperationIds: [
/// openai
"createChatCompletion",
"createEmbedding",
"listModels",
/// googleapis
"generativelanguage.tunedModels.streamGenerateContent",
"generativelanguage.models.embedContent",
"generativelanguage.tunedModels.create",
],
unusedComponents: ["schemas"],
preserveEmptyObjects: false,
},
defaultFilter: {},
})

const ast = await openapiTS(res, {
excludeDeprecated: false,
cwd: "",
alphabetize: true,
Expand Down
Loading

0 comments on commit 3de240b

Please sign in to comment.