1+ import type { Plugin } from "@hey-api/openapi-ts" ;
12import { 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
339export 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