Skip to content

Commit 3bf0434

Browse files
committed
fix: error type
1 parent 7a44544 commit 3bf0434

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

openapi-ts.config.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
1+
import type { Plugin } from "@hey-api/openapi-ts";
12
import { defineConfig } from "@hey-api/openapi-ts";
3+
import ts from "typescript";
4+
5+
const customPlugin: Plugin.Config<{ name: "vrchat/custom-plugin" }> = {
6+
name: "vrchat/custom-plugin",
7+
_handler: ({ context }) => {
8+
const typesFile = context.file({ id: "types" })!;
9+
10+
context.subscribe("after", () => {
11+
const items = (typesFile as any)._items as Array<ts.Node>;
12+
13+
// type _Error = { ... }
14+
// ->
15+
// import { VRChatError } from "../error";
16+
// type _Error = VRChatError;
17+
18+
const errorTypeName = "_Error";
19+
const errorTypeIndex = items.findIndex((item: ts.Node) => ts.isTypeAliasDeclaration(item) && item.name.text === errorTypeName);
20+
if (errorTypeIndex === -1) throw new Error("Could not find error type definition");
21+
22+
const { name: errorImport } = typesFile.import({ module: "../error", name: "VRChatError", asType: true });
23+
const errorImportIdentifier = ts.factory.createIdentifier(errorImport);
24+
25+
items[errorTypeIndex] = ts.factory.createTypeAliasDeclaration(
26+
undefined,
27+
ts.factory.createIdentifier(errorTypeName),
28+
undefined,
29+
ts.factory.createTypeReferenceNode(
30+
errorImportIdentifier,
31+
undefined
32+
)
33+
);
34+
});
35+
},
36+
_handlerLegacy: () => { },
37+
};
238

339
export default defineConfig({
4-
input: "https://vrchat.community/openapi.yaml",
40+
input: "./openapi.yaml",
541
output: "src/generated",
642
plugins: [
743
{
@@ -25,5 +61,6 @@ export default defineConfig({
2561
transformer: true,
2662
classNameBuilder: () => "_VRChat",
2763
},
64+
customPlugin as any
2865
],
2966
});

0 commit comments

Comments
 (0)