1
+ import type { Plugin } from "@hey-api/openapi-ts" ;
1
2
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
+ } ;
2
38
3
39
export default defineConfig ( {
4
- input : "https://vrchat.community /openapi.yaml" ,
40
+ input : ". /openapi.yaml" ,
5
41
output : "src/generated" ,
6
42
plugins : [
7
43
{
@@ -25,5 +61,6 @@ export default defineConfig({
25
61
transformer : true ,
26
62
classNameBuilder : ( ) => "_VRChat" ,
27
63
} ,
64
+ customPlugin as any
28
65
] ,
29
66
} ) ;
0 commit comments