fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #2185 from hey-api/refactor/plugin-api

refactor: clean up more plugin types

authored by

Lubos and committed by
GitHub
eb4fb3b1 d20e3a99

+649 -526
+10 -10
docs/openapi-ts/plugins/custom.md
··· 59 59 Reserved fields are prefixed with an underscore and are not exposed to the user. 60 60 ::: 61 61 62 - `config.ts` contains the runtime configuration for your plugin. It must implement the `Config` interface we created above and define `_handler()` and `_handlerLegacy()` functions from the `Plugin.Config` interface. 62 + `config.ts` contains the runtime configuration for your plugin. It must implement the `Config` interface we created above and define `handler()` and `handlerLegacy()` functions from the `Plugin.Config` interface. 63 63 64 64 ::: code-group 65 65 ··· 70 70 import type { Config } from './types'; 71 71 72 72 export const defaultConfig: Plugin.Config<Config> = { 73 - _dependencies: ['@hey-api/typescript'], 74 - _handler: handler, 75 - _handlerLegacy: () => {}, 76 73 config: { 77 74 myOption: false, // implements default value from types 78 75 }, 76 + dependencies: ['@hey-api/typescript'], 77 + handler, 78 + handlerLegacy: () => {}, 79 79 name: 'my-plugin', 80 80 output: 'my-plugin', 81 81 }; ··· 101 101 102 102 ## Handler 103 103 104 - Notice we defined `_handler` in our `config.ts` file. This method is responsible for generating the actual output. We recommend implementing it in `plugin.ts`. 104 + Notice we defined `handler` in our `config.ts` file. This method is responsible for generating the actual output. We recommend implementing it in `plugin.ts`. 105 105 106 106 ::: code-group 107 107 ··· 118 118 path: plugin.output, 119 119 }); 120 120 121 - context.subscribe('before', () => { 121 + plugin.subscribe('before', () => { 122 122 // do something before parsing the input 123 123 }); 124 124 125 - context.subscribe('operation', ({ operation }) => { 125 + plugin.subscribe('operation', ({ operation }) => { 126 126 // do something with the operation model 127 127 }); 128 128 129 - context.subscribe('schema', ({ operation }) => { 129 + plugin.subscribe('schema', ({ operation }) => { 130 130 // do something with the schema model 131 131 }); 132 132 133 - context.subscribe('after', () => { 133 + plugin.subscribe('after', () => { 134 134 // do something after parsing the input 135 135 }); 136 136 ··· 159 159 160 160 ### Legacy 161 161 162 - Notice we defined `_handlerLegacy` in our `config.ts` file. This method is responsible for generating the actual output when using the legacy parser. We do not recommend implementing this method unless you must use the legacy parser. You can use one of our [`plugin-legacy.ts`](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/%40hey-api/typescript/plugin-legacy.ts) files as an inspiration for potential implementation. 162 + Notice we defined `handlerLegacy` in our `config.ts` file. This method is responsible for generating the actual output when using the legacy parser. We do not recommend implementing this method unless you must use the legacy parser. You can use one of our [`plugin-legacy.ts`](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/%40hey-api/typescript/plugin-legacy.ts) files as an inspiration for potential implementation. 163 163 164 164 ## Usage 165 165
+2 -2
packages/custom-client/src/plugin.ts
··· 16 16 17 17 export const defaultConfig: Plugin.Config<Config> = { 18 18 ...clientDefaultMeta, 19 - _handler: clientPluginHandler, 20 - _handlerLegacy: () => {}, 21 19 config: { 22 20 ...clientDefaultConfig, 23 21 bundle: false, 24 22 }, 23 + handler: clientPluginHandler, 24 + handlerLegacy: () => {}, 25 25 name: '@hey-api/custom-client', 26 26 }; 27 27
+1 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/base-url-false/client/plugin.ts
··· 16 16 17 17 export const defaultConfig: Plugin.Config<Config> = { 18 18 ...clientDefaultMeta, 19 - _handler: clientPluginHandler, 20 19 config: clientDefaultConfig, 20 + handler: clientPluginHandler, 21 21 name: __filename, 22 22 }; 23 23
+1 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/base-url-number/client/plugin.ts
··· 16 16 17 17 export const defaultConfig: Plugin.Config<Config> = { 18 18 ...clientDefaultMeta, 19 - _handler: clientPluginHandler, 20 19 config: clientDefaultConfig, 20 + handler: clientPluginHandler, 21 21 name: __filename, 22 22 }; 23 23
+1 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/base-url-strict/client/plugin.ts
··· 16 16 17 17 export const defaultConfig: Plugin.Config<Config> = { 18 18 ...clientDefaultMeta, 19 - _handler: clientPluginHandler, 20 19 config: clientDefaultConfig, 20 + handler: clientPluginHandler, 21 21 name: __filename, 22 22 }; 23 23
+1 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/base-url-string/client/plugin.ts
··· 16 16 17 17 export const defaultConfig: Plugin.Config<Config> = { 18 18 ...clientDefaultMeta, 19 - _handler: clientPluginHandler, 20 19 config: clientDefaultConfig, 20 + handler: clientPluginHandler, 21 21 name: __filename, 22 22 }; 23 23
+1 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/bundle/client/plugin.ts
··· 16 16 17 17 export const defaultConfig: Plugin.Config<Config> = { 18 18 ...clientDefaultMeta, 19 - _handler: clientPluginHandler, 20 19 config: clientDefaultConfig, 20 + handler: clientPluginHandler, 21 21 name: __filename, 22 22 }; 23 23
+1 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/default/client/plugin.ts
··· 16 16 17 17 export const defaultConfig: Plugin.Config<Config> = { 18 18 ...clientDefaultMeta, 19 - _handler: clientPluginHandler, 20 19 config: clientDefaultConfig, 20 + handler: clientPluginHandler, 21 21 name: __filename, 22 22 }; 23 23
+1 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/sdk-client-optional/client/plugin.ts
··· 16 16 17 17 export const defaultConfig: Plugin.Config<Config> = { 18 18 ...clientDefaultMeta, 19 - _handler: clientPluginHandler, 20 19 config: clientDefaultConfig, 20 + handler: clientPluginHandler, 21 21 name: __filename, 22 22 }; 23 23
+1 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/sdk-client-required/client/plugin.ts
··· 16 16 17 17 export const defaultConfig: Plugin.Config<Config> = { 18 18 ...clientDefaultMeta, 19 - _handler: clientPluginHandler, 20 19 config: clientDefaultConfig, 20 + handler: clientPluginHandler, 21 21 name: __filename, 22 22 }; 23 23
+1 -1
packages/openapi-ts-tests/test/custom/client/plugin.ts
··· 16 16 17 17 export const defaultConfig: Plugin.Config<Config> = { 18 18 ...clientDefaultMeta, 19 - _handler: clientPluginHandler, 20 19 config: clientDefaultConfig, 20 + handler: clientPluginHandler, 21 21 name: __filename, 22 22 }; 23 23
+10 -10
packages/openapi-ts-tests/test/openapi-ts.config.ts
··· 57 57 // 'invalid', 58 58 // 'servers-entry.yaml', 59 59 // ), 60 - // path: path.resolve(__dirname, 'spec', '3.1.x', 'full.yaml'), 61 - path: path.resolve(__dirname, 'spec', 'v3-transforms.json'), 60 + path: path.resolve(__dirname, 'spec', '3.1.x', 'full.yaml'), 61 + // path: path.resolve(__dirname, 'spec', 'v3-transforms.json'), 62 62 // path: 'http://localhost:4000/', 63 63 // path: 'https://get.heyapi.dev/', 64 64 // path: 'https://get.heyapi.dev/hey-api/backend?branch=main&version=1.0.0', ··· 94 94 // ), 95 95 }, 96 96 plugins: [ 97 - // customClientPlugin({ 98 - // baseUrl: false, 99 - // }), 97 + customClientPlugin({ 98 + baseUrl: false, 99 + }), 100 100 // myClientPlugin(), 101 101 { 102 102 // baseUrl: false, 103 103 // exportFromIndex: true, 104 104 // name: '@hey-api/client-fetch', 105 - name: 'legacy/angular', 105 + // name: 'legacy/angular', 106 106 // strictBaseUrl: true, 107 107 // throwOnError: true, 108 108 }, ··· 138 138 // enumsConstantsIgnoreNull: true, 139 139 // exportInlineEnums: true, 140 140 // identifierCase: 'snake_case', 141 - // name: '@hey-api/typescript', 141 + name: '@hey-api/typescript', 142 142 // readOnlyWriteOnlyBehavior: 'off', 143 143 // readableNameBuilder: 'Readable{{name}}', 144 144 // writableNameBuilder: 'Writable{{name}}', ··· 152 152 infiniteQueryKeyNameBuilder: '{{name}}IQK', 153 153 infiniteQueryOptionsNameBuilder: '{{name}}InfiniteQuery', 154 154 mutationOptionsNameBuilder: '{{name}}MutationOptions', 155 - // name: '@tanstack/react-query', 155 + name: '@tanstack/react-query', 156 156 queryKeyNameBuilder: '{{name}}QK', 157 157 queryOptionsNameBuilder: '{{name}}Query', 158 158 }, 159 159 { 160 160 // comments: false, 161 161 // exportFromIndex: true, 162 - // name: 'valibot', 162 + name: 'valibot', 163 163 }, 164 164 { 165 165 // comments: false, 166 166 // exportFromIndex: true, 167 167 // metadata: true, 168 - // name: 'zod', 168 + name: 'zod', 169 169 }, 170 170 ], 171 171 // useOptions: false,
+10 -10
packages/openapi-ts-tests/test/plugins.test.ts
··· 473 473 name: any; 474 474 output: string; 475 475 }> = { 476 - _dependencies: ['@hey-api/typescript'], 477 - _handler: vi.fn(), 478 - _handlerLegacy: vi.fn(), 479 476 config: { 480 477 customOption: true, 481 478 }, 479 + dependencies: ['@hey-api/typescript'], 480 + handler: vi.fn(), 481 + handlerLegacy: vi.fn(), 482 482 name: 'my-plugin', 483 483 output: 'my-plugin', 484 484 }; ··· 492 492 plugins: [myPlugin, '@hey-api/client-fetch'], 493 493 }); 494 494 495 - expect(myPlugin._handler).toHaveBeenCalled(); 496 - expect(myPlugin._handlerLegacy).not.toHaveBeenCalled(); 495 + expect(myPlugin.handler).toHaveBeenCalled(); 496 + expect(myPlugin.handlerLegacy).not.toHaveBeenCalled(); 497 497 }); 498 498 499 499 it('throws on invalid dependency', async () => { ··· 501 501 name: any; 502 502 output: string; 503 503 }> = { 504 - _dependencies: ['@hey-api/oops'], 505 - _handler: vi.fn(), 506 - _handlerLegacy: vi.fn(), 507 504 config: {}, 505 + dependencies: ['@hey-api/oops'], 506 + handler: vi.fn(), 507 + handlerLegacy: vi.fn(), 508 508 name: 'my-plugin', 509 509 output: 'my-plugin', 510 510 }; ··· 520 520 }), 521 521 ).rejects.toThrowError(/unknown plugin/g); 522 522 523 - expect(myPlugin._handler).not.toHaveBeenCalled(); 524 - expect(myPlugin._handlerLegacy).not.toHaveBeenCalled(); 523 + expect(myPlugin.handler).not.toHaveBeenCalled(); 524 + expect(myPlugin.handlerLegacy).not.toHaveBeenCalled(); 525 525 }); 526 526 }); 527 527 }
+9 -9
packages/openapi-ts/src/generate/__tests__/class.test.ts
··· 42 42 ], 43 43 plugins: { 44 44 '@hey-api/schemas': { 45 - _handler: () => {}, 46 - _handlerLegacy: () => {}, 47 45 config: {}, 46 + handler: () => {}, 47 + handlerLegacy: () => {}, 48 48 name: '@hey-api/schemas', 49 49 }, 50 50 '@hey-api/sdk': { 51 - _handler: () => {}, 52 - _handlerLegacy: () => {}, 53 51 config: {}, 52 + handler: () => {}, 53 + handlerLegacy: () => {}, 54 54 name: '@hey-api/sdk', 55 55 }, 56 56 '@hey-api/typescript': { 57 - _handler: () => {}, 58 - _handlerLegacy: () => {}, 59 57 config: { 60 58 enums: 'javascript', 61 59 }, 60 + handler: () => {}, 61 + handlerLegacy: () => {}, 62 62 name: '@hey-api/typescript', 63 63 }, 64 64 'legacy/fetch': { 65 - _handler: () => {}, 66 - _handlerLegacy: () => {}, 67 - _tags: ['client'], 68 65 config: {}, 66 + handler: () => {}, 67 + handlerLegacy: () => {}, 69 68 name: 'legacy/fetch', 69 + tags: ['client'], 70 70 }, 71 71 }, 72 72 useOptions: true,
+27 -27
packages/openapi-ts/src/generate/__tests__/core.test.ts
··· 57 57 ], 58 58 plugins: { 59 59 '@hey-api/schemas': { 60 - _handler: () => {}, 61 - _handlerLegacy: () => {}, 62 60 config: {}, 61 + handler: () => {}, 62 + handlerLegacy: () => {}, 63 63 name: '@hey-api/schemas', 64 64 }, 65 65 '@hey-api/sdk': { 66 - _handler: () => {}, 67 - _handlerLegacy: () => {}, 68 66 config: {}, 67 + handler: () => {}, 68 + handlerLegacy: () => {}, 69 69 name: '@hey-api/sdk', 70 70 }, 71 71 '@hey-api/typescript': { 72 - _handler: () => {}, 73 - _handlerLegacy: () => {}, 74 72 config: { 75 73 enums: 'javascript', 76 74 }, 75 + handler: () => {}, 76 + handlerLegacy: () => {}, 77 77 name: '@hey-api/typescript', 78 78 }, 79 79 'legacy/fetch': { 80 - _handler: () => {}, 81 - _handlerLegacy: () => {}, 82 - _tags: ['client'], 83 80 config: {}, 81 + handler: () => {}, 82 + handlerLegacy: () => {}, 84 83 name: 'legacy/fetch', 84 + tags: ['client'], 85 85 }, 86 86 }, 87 87 useOptions: true, ··· 156 156 ], 157 157 plugins: { 158 158 '@hey-api/schemas': { 159 - _handler: () => {}, 160 - _handlerLegacy: () => {}, 161 159 config: {}, 160 + handler: () => {}, 161 + handlerLegacy: () => {}, 162 162 name: '@hey-api/schemas', 163 163 }, 164 164 '@hey-api/sdk': { 165 - _handler: () => {}, 166 - _handlerLegacy: () => {}, 167 165 config: {}, 166 + handler: () => {}, 167 + handlerLegacy: () => {}, 168 168 name: '@hey-api/sdk', 169 169 }, 170 170 '@hey-api/typescript': { 171 - _handler: () => {}, 172 - _handlerLegacy: () => {}, 173 171 config: { 174 172 enums: 'javascript', 175 173 }, 174 + handler: () => {}, 175 + handlerLegacy: () => {}, 176 176 name: '@hey-api/typescript', 177 177 }, 178 178 'legacy/fetch': { 179 - _handler: () => {}, 180 - _handlerLegacy: () => {}, 181 - _tags: ['client'], 182 179 config: {}, 180 + handler: () => {}, 181 + handlerLegacy: () => {}, 183 182 name: 'legacy/fetch', 183 + tags: ['client'], 184 184 }, 185 185 }, 186 186 useOptions: true, ··· 238 238 ], 239 239 plugins: { 240 240 '@hey-api/schemas': { 241 - _handler: () => {}, 242 - _handlerLegacy: () => {}, 243 241 config: {}, 242 + handler: () => {}, 243 + handlerLegacy: () => {}, 244 244 name: '@hey-api/schemas', 245 245 }, 246 246 '@hey-api/sdk': { 247 - _handler: () => {}, 248 - _handlerLegacy: () => {}, 249 247 config: {}, 248 + handler: () => {}, 249 + handlerLegacy: () => {}, 250 250 name: '@hey-api/sdk', 251 251 }, 252 252 '@hey-api/typescript': { 253 - _handler: () => {}, 254 - _handlerLegacy: () => {}, 255 253 config: { 256 254 enums: 'javascript', 257 255 }, 256 + handler: () => {}, 257 + handlerLegacy: () => {}, 258 258 name: '@hey-api/typescript', 259 259 }, 260 260 'legacy/fetch': { 261 - _handler: () => {}, 262 - _handlerLegacy: () => {}, 263 - _tags: ['client'], 264 261 config: {}, 262 + handler: () => {}, 263 + handlerLegacy: () => {}, 265 264 name: 'legacy/fetch', 265 + tags: ['client'], 266 266 }, 267 267 }, 268 268 useOptions: true,
+9 -9
packages/openapi-ts/src/generate/legacy/__tests__/index.test.ts
··· 41 41 ], 42 42 plugins: { 43 43 '@hey-api/schemas': { 44 - _handler: () => {}, 45 - _handlerLegacy: () => {}, 46 44 config: {}, 45 + handler: () => {}, 46 + handlerLegacy: () => {}, 47 47 name: '@hey-api/schemas', 48 48 }, 49 49 '@hey-api/sdk': { 50 - _handler: () => {}, 51 - _handlerLegacy: () => {}, 52 50 config: {}, 51 + handler: () => {}, 52 + handlerLegacy: () => {}, 53 53 name: '@hey-api/sdk', 54 54 }, 55 55 '@hey-api/typescript': { 56 - _handler: () => {}, 57 - _handlerLegacy: () => {}, 58 56 config: { 59 57 enums: 'javascript', 60 58 }, 59 + handler: () => {}, 60 + handlerLegacy: () => {}, 61 61 name: '@hey-api/typescript', 62 62 }, 63 63 'legacy/fetch': { 64 - _handler: () => {}, 65 - _handlerLegacy: () => {}, 66 - _tags: ['client'], 67 64 config: {}, 65 + handler: () => {}, 66 + handlerLegacy: () => {}, 68 67 name: 'legacy/fetch', 68 + tags: ['client'], 69 69 }, 70 70 }, 71 71 useOptions: true,
+9 -9
packages/openapi-ts/src/generate/legacy/__tests__/output.test.ts
··· 55 55 ], 56 56 plugins: { 57 57 '@hey-api/schemas': { 58 - _handler: () => {}, 59 - _handlerLegacy: () => {}, 60 58 config: {}, 59 + handler: () => {}, 60 + handlerLegacy: () => {}, 61 61 name: '@hey-api/schemas', 62 62 }, 63 63 '@hey-api/sdk': { 64 - _handler: () => {}, 65 - _handlerLegacy: () => {}, 66 64 config: {}, 65 + handler: () => {}, 66 + handlerLegacy: () => {}, 67 67 name: '@hey-api/sdk', 68 68 }, 69 69 '@hey-api/typescript': { 70 - _handler: () => {}, 71 - _handlerLegacy: () => {}, 72 70 config: { 73 71 enums: 'javascript', 74 72 }, 73 + handler: () => {}, 74 + handlerLegacy: () => {}, 75 75 name: '@hey-api/typescript', 76 76 }, 77 77 'legacy/fetch': { 78 - _handler: () => {}, 79 - _handlerLegacy: () => {}, 80 - _tags: ['client'], 81 78 config: {}, 79 + handler: () => {}, 80 + handlerLegacy: () => {}, 82 81 name: 'legacy/fetch', 82 + tags: ['client'], 83 83 }, 84 84 }, 85 85 useOptions: false,
+1 -1
packages/openapi-ts/src/generate/legacy/output.ts
··· 96 96 id: `legacy-unused-${plugin.name}`, 97 97 name: `${outputParts[outputParts.length - 1]}.ts`, 98 98 }); 99 - plugin._handlerLegacy({ 99 + plugin.handlerLegacy({ 100 100 client, 101 101 files, 102 102 openApi: spec,
+2 -15
packages/openapi-ts/src/generate/output.ts
··· 3 3 import ts from 'typescript'; 4 4 5 5 import { compiler } from '../compiler'; 6 - import type { Events } from '../ir/context'; 7 6 import { parseIR } from '../ir/parser'; 8 7 import type { IR } from '../ir/types'; 9 8 import { getClientPlugin } from '../plugins/@hey-api/client-core/utils'; ··· 33 32 }); 34 33 } 35 34 36 - for (const name of context.config.pluginOrder) { 37 - const plugin = context.config.plugins[name]!; 38 - const _subscribe = context.subscribe.bind(context); 39 - context.subscribe = <T extends keyof Events>( 40 - event: T, 41 - callbackFn: Events[T], 42 - ): void => { 43 - _subscribe(event, callbackFn, name); 44 - }; 45 - plugin._handler({ 46 - context, 47 - plugin: plugin as never, 48 - }); 49 - context.subscribe = _subscribe; 35 + for (const plugin of context.registerPlugins()) { 36 + plugin.run(); 50 37 } 51 38 52 39 await parseIR({ context });
+14 -14
packages/openapi-ts/src/initConfigs.ts
··· 110 110 } 111 111 112 112 const plugin = { 113 - _dependencies: [], 114 113 ...defaultPlugin, 115 114 ...userPlugin, 116 115 config: { 117 116 ...defaultPlugin?.config, 118 117 ...userPlugin?.config, 119 118 }, 119 + dependencies: new Set([ 120 + ...(defaultPlugin?.dependencies || []), 121 + ...(userPlugin?.dependencies || []), 122 + ]), 120 123 }; 121 124 122 - if (plugin._infer) { 125 + if (plugin.resolveConfig) { 123 126 const context: PluginContext = { 124 - ensureDependency: (dependency) => { 125 - if (!plugin._dependencies.includes(dependency)) { 126 - plugin._dependencies = [...plugin._dependencies, dependency]; 127 - } 128 - }, 129 - pluginByTag: ({ defaultPlugin, errorMessage, tag }) => { 127 + pluginByTag: (tag, props = {}) => { 128 + const { defaultPlugin, errorMessage } = props; 129 + 130 130 for (const userPlugin of userPlugins) { 131 131 const defaultConfig = 132 132 defaultPluginConfigs[userPlugin as PluginNames] || 133 133 userPluginsConfig[userPlugin as PluginNames]; 134 134 if ( 135 135 defaultConfig && 136 - defaultConfig._tags?.includes(tag) && 136 + defaultConfig.tags?.includes(tag) && 137 137 userPlugin !== name 138 138 ) { 139 139 return userPlugin as any; ··· 146 146 userPluginsConfig[defaultPlugin as PluginNames]; 147 147 if ( 148 148 defaultConfig && 149 - defaultConfig._tags?.includes(tag) && 149 + defaultConfig.tags?.includes(tag) && 150 150 defaultPlugin !== name 151 151 ) { 152 152 return defaultPlugin; ··· 160 160 }, 161 161 }; 162 162 // @ts-expect-error 163 - plugin._infer(plugin, context); 163 + plugin.resolveConfig(plugin, context); 164 164 } 165 165 166 - for (const dependency of plugin._dependencies) { 166 + for (const dependency of plugin.dependencies) { 167 167 dfs(dependency); 168 168 } 169 169 ··· 213 213 plugin.name.startsWith('@hey-api/client') || 214 214 plugin.name.startsWith('legacy/') || 215 215 // @ts-expect-error 216 - (plugin._tags && plugin._tags.includes('client')) 216 + (plugin.tags && plugin.tags.includes('client')) 217 217 ); 218 218 }; 219 219 ··· 250 250 251 251 if (pluginName) { 252 252 // @ts-expect-error 253 - if (plugin._handler) { 253 + if (plugin.handler) { 254 254 // @ts-expect-error 255 255 userPluginsConfig[pluginName] = plugin; 256 256 } else {
+52 -2
packages/openapi-ts/src/ir/context.ts
··· 2 2 3 3 import { HeyApiError } from '../error'; 4 4 import { TypeScriptFile } from '../generate/files'; 5 + import { PluginInstance } from '../plugins/shared/utils/instance'; 5 6 import type { Config, StringCase } from '../types/config'; 6 7 import type { Files } from '../types/utils'; 7 8 import { resolveRef } from '../utils/ref'; 8 9 import type { IR } from './types'; 9 10 10 - interface ContextFile { 11 + // Helper type to extract the original config type from Plugin.Config and ensure it satisfies BaseConfig 12 + type ExtractConfig<T> = T extends { config: infer C } 13 + ? C & { name: string } 14 + : never; 15 + 16 + // Helper type to map plugin names to their specific PluginInstance types 17 + type PluginInstanceMap = { 18 + [K in keyof Config['plugins']]?: PluginInstance< 19 + ExtractConfig<Config['plugins'][K]> 20 + >; 21 + }; 22 + 23 + export interface ContextFile { 11 24 /** 12 25 * Should the exports from this file be re-exported in the index barrel file? 13 26 */ ··· 22 35 identifierCase?: StringCase; 23 36 /** 24 37 * Relative file path to the output path. 38 + * 25 39 * @example 26 40 * 'bar/foo.ts' 27 41 */ ··· 83 97 * Intermediate representation model obtained from `spec`. 84 98 */ 85 99 public ir: IR.Model; 100 + /** 101 + * A map of registered plugin instances, keyed by plugin name. Plugins are 102 + * registered through the `registerPlugin` method and can be accessed by 103 + * their configured name from the config. 104 + */ 105 + public plugins: PluginInstanceMap = {}; 86 106 /** 87 107 * Resolved specification from `input`. 88 108 */ ··· 175 195 return this.files[id]; 176 196 } 177 197 198 + /** 199 + * Registers a new plugin to the global context. 200 + * 201 + * @param name Plugin name. 202 + * @returns Registered plugin instance. 203 + */ 204 + private registerPlugin(name: keyof Config['plugins']): PluginInstance { 205 + const plugin = this.config.plugins[name]!; 206 + const instance = new PluginInstance({ 207 + config: plugin.config, 208 + context: this as any, 209 + dependencies: plugin.dependencies ?? [], 210 + handler: plugin.handler, 211 + name: plugin.name, 212 + output: plugin.output!, 213 + }); 214 + this.plugins[instance.name] = instance; 215 + return instance; 216 + } 217 + 218 + /** 219 + * Generator that iterates through plugin order and registers each plugin. 220 + * Yields the registered plugin instance for each plugin name. 221 + */ 222 + public *registerPlugins(): Generator<PluginInstance> { 223 + for (const name of this.config.pluginOrder) { 224 + yield this.registerPlugin(name); 225 + } 226 + } 227 + 178 228 // TODO: parser - works the same as resolveRef, but for IR schemas. 179 229 // for now, they map 1:1, but if they diverge (like with OpenAPI 2.0), 180 230 // we will want to rewrite $refs at parse time, so they continue pointing ··· 202 252 public subscribe<T extends keyof Events>( 203 253 event: T, 204 254 callbackFn: Events[T], 205 - pluginName?: string, 255 + pluginName: string, 206 256 ): void { 207 257 if (!this.listeners[event]) { 208 258 this.listeners[event] = [];
+3 -1
packages/openapi-ts/src/ir/types.d.ts
··· 3 3 SecuritySchemeObject, 4 4 ServerObject, 5 5 } from '../openApi/3.1.x/types/spec'; 6 - import type { IRContext } from './context'; 6 + import type { ContextFile as CtxFile, Events, IRContext } from './context'; 7 7 import type { IRMediaType } from './mediaType'; 8 8 9 9 interface IRBodyObject { ··· 217 217 export type BodyObject = IRBodyObject; 218 218 export type ComponentsObject = IRComponentsObject; 219 219 export type Context<Spec extends Record<string, any> = any> = IRContext<Spec>; 220 + export type ContextEvents = Events; 221 + export type ContextFile = CtxFile; 220 222 export type Model = IRModel; 221 223 export type OperationObject = IROperationObject; 222 224 export type ParameterObject = IRParameterObject;
+2 -2
packages/openapi-ts/src/openApi/common/parser/__tests__/type.test.ts
··· 7 7 const config: Partial<Config> = { 8 8 plugins: { 9 9 '@hey-api/typescript': { 10 - _handler: () => {}, 11 - _handlerLegacy: () => {}, 12 10 config: {}, 11 + handler: () => {}, 12 + handlerLegacy: () => {}, 13 13 name: '@hey-api/typescript', 14 14 }, 15 15 },
+2 -2
packages/openapi-ts/src/openApi/v3/parser/__tests__/getModel.test.ts
··· 9 9 const config: Partial<Config> = { 10 10 plugins: { 11 11 '@hey-api/typescript': { 12 - _handler: () => {}, 13 - _handlerLegacy: () => {}, 14 12 config: {}, 13 + handler: () => {}, 14 + handlerLegacy: () => {}, 15 15 name: '@hey-api/typescript', 16 16 }, 17 17 },
+1 -1
packages/openapi-ts/src/plugins/@hey-api/client-axios/config.ts
··· 6 6 7 7 export const defaultConfig: Plugin.Config<Config> = { 8 8 ...clientDefaultMeta, 9 - _handler: clientPluginHandler, 10 9 config: { 11 10 ...clientDefaultConfig, 12 11 throwOnError: false, 13 12 }, 13 + handler: clientPluginHandler, 14 14 name: '@hey-api/client-axios', 15 15 }; 16 16
+9 -10
packages/openapi-ts/src/plugins/@hey-api/client-core/client.ts
··· 6 6 import { clientId, getClientBaseUrlKey } from './utils'; 7 7 8 8 const resolveBaseUrlString: PluginHandler<string | undefined> = ({ 9 - context, 10 9 plugin, 11 10 }) => { 12 11 const { baseUrl } = plugin.config; ··· 19 18 return baseUrl; 20 19 } 21 20 22 - const { servers } = context.ir; 21 + const { servers } = plugin.context.ir; 23 22 24 23 if (!servers) { 25 24 return; ··· 28 27 return servers[typeof baseUrl === 'number' ? baseUrl : 0]?.url; 29 28 }; 30 29 31 - export const createClient: PluginHandler = ({ context, plugin }) => { 32 - const file = context.file({ id: clientId })!; 30 + export const createClient: PluginHandler = ({ plugin }) => { 31 + const file = plugin.context.file({ id: clientId })!; 33 32 34 33 const clientModule = clientModulePath({ 35 - config: context.config, 34 + config: plugin.context.config, 36 35 sourceOutput: file.nameWithoutExtension(), 37 36 }); 38 37 const createClient = file.import({ ··· 45 44 }); 46 45 const clientOptions = file.import({ 47 46 asType: true, 48 - module: file.relativePathToFile({ context, id: typesId }), 47 + module: file.relativePathToFile({ context: plugin.context, id: typesId }), 49 48 name: 'ClientOptions', 50 49 }); 51 50 52 51 const createClientConfig = plugin.config.runtimeConfigPath 53 52 ? file.import({ 54 53 module: file.relativePathToFile({ 55 - context, 54 + context: plugin.context, 56 55 id: plugin.config.runtimeConfigPath, 57 56 }), 58 57 name: 'createClientConfig', ··· 61 60 62 61 const defaultValues: Array<unknown> = []; 63 62 64 - const resolvedBaseUrl = resolveBaseUrlString({ context, plugin }); 63 + const resolvedBaseUrl = resolveBaseUrlString({ plugin }); 65 64 if (resolvedBaseUrl) { 66 65 const url = parseUrl(resolvedBaseUrl); 67 66 if (url.protocol && url.host && !resolvedBaseUrl.includes('{')) { 68 67 defaultValues.push({ 69 - key: getClientBaseUrlKey(context.config), 68 + key: getClientBaseUrlKey(plugin.context.config), 70 69 value: resolvedBaseUrl, 71 70 }); 72 71 } else if (resolvedBaseUrl !== '/' && resolvedBaseUrl.startsWith('/')) { ··· 74 73 ? resolvedBaseUrl.slice(0, -1) 75 74 : resolvedBaseUrl; 76 75 defaultValues.push({ 77 - key: getClientBaseUrlKey(context.config), 76 + key: getClientBaseUrlKey(plugin.context.config), 78 77 value: baseUrl, 79 78 }); 80 79 }
+3 -3
packages/openapi-ts/src/plugins/@hey-api/client-core/config.ts
··· 5 5 } as const; 6 6 7 7 export const clientDefaultMeta = { 8 - _dependencies: ['@hey-api/typescript'], 9 - _handlerLegacy: () => {}, 10 - _tags: ['client'], 8 + dependencies: ['@hey-api/typescript'], 9 + handlerLegacy: () => {}, 11 10 output: 'client', 11 + tags: ['client'], 12 12 } as const;
+4 -4
packages/openapi-ts/src/plugins/@hey-api/client-core/createClientConfig.ts
··· 4 4 import { typesId } from '../typescript/ref'; 5 5 import type { PluginHandler } from './types'; 6 6 7 - export const createClientConfigType: PluginHandler = ({ context }) => { 8 - const file = context.file({ id: clientId })!; 7 + export const createClientConfigType: PluginHandler = ({ plugin }) => { 8 + const file = plugin.context.file({ id: clientId })!; 9 9 10 10 const clientModule = clientModulePath({ 11 - config: context.config, 11 + config: plugin.context.config, 12 12 sourceOutput: file.nameWithoutExtension(), 13 13 }); 14 14 const clientOptions = file.import({ 15 15 asType: true, 16 - module: file.relativePathToFile({ context, id: typesId }), 16 + module: file.relativePathToFile({ context: plugin.context, id: typesId }), 17 17 name: 'ClientOptions', 18 18 }); 19 19 const configType = file.import({
+4 -5
packages/openapi-ts/src/plugins/@hey-api/client-core/plugin.ts
··· 3 3 import { createClientConfigType } from './createClientConfig'; 4 4 import type { PluginHandler } from './types'; 5 5 6 - export const clientPluginHandler: PluginHandler = ({ context, plugin }) => { 7 - context.createFile({ 8 - exportFromIndex: plugin.config.exportFromIndex, 6 + export const clientPluginHandler: PluginHandler = ({ plugin }) => { 7 + plugin.createFile({ 9 8 id: clientId, 10 9 path: plugin.output, 11 10 }); 12 11 13 - createClientConfigType({ context, plugin }); 14 - createClient({ context, plugin }); 12 + createClientConfigType({ plugin }); 13 + createClient({ plugin }); 15 14 };
+1 -4
packages/openapi-ts/src/plugins/@hey-api/client-core/types.d.ts
··· 5 5 import type { Config as ClientNuxtConfig } from '../client-nuxt'; 6 6 7 7 export type PluginHandler<ReturnType = void> = Plugin.Handler< 8 - Omit< 9 - ClientAxiosConfig | ClientFetchConfig | ClientNextConfig | ClientNuxtConfig, 10 - 'name' 11 - >, 8 + ClientAxiosConfig | ClientFetchConfig | ClientNextConfig | ClientNuxtConfig, 12 9 ReturnType 13 10 >; 14 11
+1 -1
packages/openapi-ts/src/plugins/@hey-api/client-core/utils.ts
··· 21 21 ): Required<Plugins>[PluginClientNames] => { 22 22 for (const name of config.pluginOrder) { 23 23 const plugin = config.plugins[name]; 24 - if (plugin?._tags?.includes('client')) { 24 + if (plugin?.tags?.includes('client')) { 25 25 return plugin as Required<Plugins>[PluginClientNames]; 26 26 } 27 27 }
+1 -1
packages/openapi-ts/src/plugins/@hey-api/client-fetch/config.ts
··· 6 6 7 7 export const defaultConfig: Plugin.Config<Config> = { 8 8 ...clientDefaultMeta, 9 - _handler: clientPluginHandler, 10 9 config: { 11 10 ...clientDefaultConfig, 12 11 throwOnError: false, 13 12 }, 13 + handler: clientPluginHandler, 14 14 name: '@hey-api/client-fetch', 15 15 }; 16 16
+1 -1
packages/openapi-ts/src/plugins/@hey-api/client-next/config.ts
··· 6 6 7 7 export const defaultConfig: Plugin.Config<Config> = { 8 8 ...clientDefaultMeta, 9 - _handler: clientPluginHandler, 10 9 config: { 11 10 ...clientDefaultConfig, 12 11 throwOnError: false, 13 12 }, 13 + handler: clientPluginHandler, 14 14 name: '@hey-api/client-next', 15 15 }; 16 16
+1 -1
packages/openapi-ts/src/plugins/@hey-api/client-nuxt/config.ts
··· 6 6 7 7 export const defaultConfig: Plugin.Config<Config> = { 8 8 ...clientDefaultMeta, 9 - _handler: clientPluginHandler, 10 9 config: clientDefaultConfig, 10 + handler: clientPluginHandler, 11 11 name: '@hey-api/client-nuxt', 12 12 }; 13 13
+3 -3
packages/openapi-ts/src/plugins/@hey-api/legacy-angular/config.ts
··· 3 3 import type { Config } from './types'; 4 4 5 5 export const defaultConfig: Plugin.Config<Config> = { 6 - _handler: () => {}, 7 - _handlerLegacy: () => {}, 8 - _tags: ['client'], 9 6 config: {}, 7 + handler: () => {}, 8 + handlerLegacy: () => {}, 10 9 name: 'legacy/angular', 11 10 output: 'client', 11 + tags: ['client'], 12 12 }; 13 13 14 14 /**
+3 -3
packages/openapi-ts/src/plugins/@hey-api/legacy-axios/config.ts
··· 3 3 import type { Config } from './types'; 4 4 5 5 export const defaultConfig: Plugin.Config<Config> = { 6 - _handler: () => {}, 7 - _handlerLegacy: () => {}, 8 - _tags: ['client'], 9 6 config: {}, 7 + handler: () => {}, 8 + handlerLegacy: () => {}, 10 9 name: 'legacy/axios', 11 10 output: 'client', 11 + tags: ['client'], 12 12 }; 13 13 14 14 /**
+3 -3
packages/openapi-ts/src/plugins/@hey-api/legacy-fetch/config.ts
··· 3 3 import type { Config } from './types'; 4 4 5 5 export const defaultConfig: Plugin.Config<Config> = { 6 - _handler: () => {}, 7 - _handlerLegacy: () => {}, 8 - _tags: ['client'], 9 6 config: {}, 7 + handler: () => {}, 8 + handlerLegacy: () => {}, 10 9 name: 'legacy/fetch', 11 10 output: 'client', 11 + tags: ['client'], 12 12 }; 13 13 14 14 /**
+3 -3
packages/openapi-ts/src/plugins/@hey-api/legacy-node/config.ts
··· 3 3 import type { Config } from './types'; 4 4 5 5 export const defaultConfig: Plugin.Config<Config> = { 6 - _handler: () => {}, 7 - _handlerLegacy: () => {}, 8 - _tags: ['client'], 9 6 config: {}, 7 + handler: () => {}, 8 + handlerLegacy: () => {}, 10 9 name: 'legacy/node', 11 10 output: 'client', 11 + tags: ['client'], 12 12 }; 13 13 14 14 /**
+3 -3
packages/openapi-ts/src/plugins/@hey-api/legacy-xhr/config.ts
··· 3 3 import type { Config } from './types'; 4 4 5 5 export const defaultConfig: Plugin.Config<Config> = { 6 - _handler: () => {}, 7 - _handlerLegacy: () => {}, 8 - _tags: ['client'], 9 6 config: {}, 7 + handler: () => {}, 8 + handlerLegacy: () => {}, 10 9 name: 'legacy/xhr', 11 10 output: 'client', 11 + tags: ['client'], 12 12 }; 13 13 14 14 /**
+29 -22
packages/openapi-ts/src/plugins/@hey-api/schemas/__tests__/schemas.test.ts
··· 6 6 import type { OpenApiV3Schema } from '../../../../openApi'; 7 7 import type { Files } from '../../../../types/utils'; 8 8 import { setConfig } from '../../../../utils/config'; 9 + import { PluginInstance } from '../../../shared/utils/instance'; 9 10 import { handlerLegacy } from '../plugin-legacy'; 10 11 11 12 vi.mock('node:fs'); ··· 43 44 ], 44 45 plugins: { 45 46 '@hey-api/schemas': { 46 - _handler: () => {}, 47 - _handlerLegacy: () => {}, 48 47 config: {}, 48 + handler: () => {}, 49 + handlerLegacy: () => {}, 49 50 name: '@hey-api/schemas', 50 51 }, 51 52 '@hey-api/sdk': { 52 - _handler: () => {}, 53 - _handlerLegacy: () => {}, 54 53 config: {}, 54 + handler: () => {}, 55 + handlerLegacy: () => {}, 55 56 name: '@hey-api/sdk', 56 57 }, 57 58 '@hey-api/typescript': { 58 - _handler: () => {}, 59 - _handlerLegacy: () => {}, 60 59 config: { 61 60 enums: 'javascript', 62 61 }, 62 + handler: () => {}, 63 + handlerLegacy: () => {}, 63 64 name: '@hey-api/typescript', 64 65 }, 65 66 'legacy/fetch': { 66 - _handler: () => {}, 67 - _handlerLegacy: () => {}, 68 - _tags: ['client'], 69 67 config: {}, 68 + handler: () => {}, 69 + handlerLegacy: () => {}, 70 70 name: 'legacy/fetch', 71 + tags: ['client'], 71 72 }, 72 73 }, 73 74 useOptions: true, ··· 89 90 client, 90 91 files, 91 92 openApi, 92 - plugin: { 93 + plugin: new PluginInstance({ 93 94 config: { 94 95 exportFromIndex: false, 95 96 }, 97 + context: {} as any, 98 + dependencies: [], 99 + handler: () => {}, 96 100 name: '@hey-api/schemas', 97 101 output: 'schemas', 98 - }, 102 + }), 99 103 }); 100 104 101 105 files.schemas!.write(); ··· 140 144 ], 141 145 plugins: { 142 146 '@hey-api/schemas': { 143 - _handler: () => {}, 144 - _handlerLegacy: () => {}, 145 147 config: { 146 148 nameBuilder: nameFn, 147 149 }, 150 + handler: () => {}, 151 + handlerLegacy: () => {}, 148 152 name: '@hey-api/schemas', 149 153 }, 150 154 '@hey-api/sdk': { 151 - _handler: () => {}, 152 - _handlerLegacy: () => {}, 153 155 config: {}, 156 + handler: () => {}, 157 + handlerLegacy: () => {}, 154 158 name: '@hey-api/sdk', 155 159 }, 156 160 '@hey-api/typescript': { 157 - _handler: () => {}, 158 - _handlerLegacy: () => {}, 159 161 config: { 160 162 enums: 'javascript', 161 163 }, 164 + handler: () => {}, 165 + handlerLegacy: () => {}, 162 166 name: '@hey-api/typescript', 163 167 }, 164 168 'legacy/fetch': { 165 - _handler: () => {}, 166 - _handlerLegacy: () => {}, 167 - _tags: ['client'], 168 169 config: {}, 170 + handler: () => {}, 171 + handlerLegacy: () => {}, 169 172 name: 'legacy/fetch', 173 + tags: ['client'], 170 174 }, 171 175 }, 172 176 useOptions: true, ··· 190 194 client, 191 195 files, 192 196 openApi, 193 - plugin: { 197 + plugin: new PluginInstance({ 194 198 config: { 195 199 exportFromIndex: false, 196 200 }, 201 + context: {} as any, 202 + dependencies: [], 203 + handler: () => {}, 197 204 name: '@hey-api/schemas', 198 205 output: 'schemas', 199 - }, 206 + }), 200 207 }); 201 208 202 209 files.schemas!.write();
+2 -2
packages/openapi-ts/src/plugins/@hey-api/schemas/config.ts
··· 5 5 import type { Config } from './types'; 6 6 7 7 export const defaultConfig: Plugin.Config<Config> = { 8 - _handler: handler, 9 - _handlerLegacy: handlerLegacy, 10 8 config: { 11 9 exportFromIndex: false, 12 10 nameBuilder: (name) => `${name}Schema`, 13 11 type: 'json', 14 12 }, 13 + handler, 14 + handlerLegacy, 15 15 name: '@hey-api/schemas', 16 16 output: 'schemas', 17 17 };
+7 -8
packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts
··· 440 440 } 441 441 }; 442 442 443 - export const handler: Plugin.Handler<Config> = ({ context, plugin }) => { 444 - context.createFile({ 445 - exportFromIndex: plugin.config.exportFromIndex, 443 + export const handler: Plugin.Handler<Config> = ({ plugin }) => { 444 + plugin.createFile({ 446 445 id: schemasId, 447 446 path: plugin.output, 448 447 }); 449 448 450 - if ('swagger' in context.spec) { 449 + if ('swagger' in plugin.context.spec) { 451 450 schemasV2_0_X({ 452 - context: context as IR.Context<OpenApi.V2_0_X>, 451 + context: plugin.context as IR.Context<OpenApi.V2_0_X>, 453 452 plugin, 454 453 }); 455 454 return; 456 455 } 457 456 458 - switch (context.spec.openapi) { 457 + switch (plugin.context.spec.openapi) { 459 458 case '3.0.0': 460 459 case '3.0.1': 461 460 case '3.0.2': 462 461 case '3.0.3': 463 462 case '3.0.4': 464 463 schemasV3_0_X({ 465 - context: context as IR.Context<OpenApi.V3_0_X>, 464 + context: plugin.context as IR.Context<OpenApi.V3_0_X>, 466 465 plugin, 467 466 }); 468 467 break; 469 468 case '3.1.0': 470 469 case '3.1.1': 471 470 schemasV3_1_X({ 472 - context: context as IR.Context<OpenApi.V3_1_X>, 471 + context: plugin.context as IR.Context<OpenApi.V3_1_X>, 473 472 plugin, 474 473 }); 475 474 break;
+57 -44
packages/openapi-ts/src/plugins/@hey-api/sdk/__tests__/plugin.test.ts
··· 9 9 import type { Config } from '../../../../types/config'; 10 10 import type { Files } from '../../../../types/utils'; 11 11 import { setConfig } from '../../../../utils/config'; 12 + import { PluginInstance } from '../../../shared/utils/instance'; 12 13 import { handlerLegacy } from '../plugin-legacy'; 13 14 14 15 vi.mock('node:fs'); ··· 45 46 ], 46 47 plugins: { 47 48 '@hey-api/schemas': { 48 - _handler: () => {}, 49 - _handlerLegacy: () => {}, 50 49 config: {}, 50 + handler: () => {}, 51 + handlerLegacy: () => {}, 51 52 name: '@hey-api/schemas', 52 53 }, 53 54 '@hey-api/sdk': { 54 - _handler: () => {}, 55 - _handlerLegacy: () => {}, 56 55 config: { 57 56 asClass: true, 58 57 }, 58 + handler: () => {}, 59 + handlerLegacy: () => {}, 59 60 name: '@hey-api/sdk', 60 61 }, 61 62 '@hey-api/typescript': { 62 - _handler: () => {}, 63 - _handlerLegacy: () => {}, 64 63 config: {}, 64 + handler: () => {}, 65 + handlerLegacy: () => {}, 65 66 name: '@hey-api/typescript', 66 67 }, 67 68 'legacy/fetch': { 68 - _handler: () => {}, 69 - _handlerLegacy: () => {}, 70 - _tags: ['client'], 71 69 config: {}, 70 + handler: () => {}, 71 + handlerLegacy: () => {}, 72 72 name: 'legacy/fetch', 73 + tags: ['client'], 73 74 }, 74 75 }, 75 76 useOptions: false, ··· 125 126 client, 126 127 files, 127 128 openApi, 128 - plugin: { 129 + plugin: new PluginInstance({ 129 130 config: { 130 131 exportFromIndex: false, 131 132 }, 133 + context: {} as any, 134 + dependencies: [], 135 + handler: () => {}, 132 136 name: '@hey-api/sdk', 133 137 output: '', 134 - }, 138 + }), 135 139 }); 136 140 137 141 files.sdk!.write(); ··· 215 219 ], 216 220 plugins: { 217 221 '@hey-api/schemas': { 218 - _handler: () => {}, 219 - _handlerLegacy: () => {}, 220 222 config: {}, 223 + handler: () => {}, 224 + handlerLegacy: () => {}, 221 225 name: '@hey-api/schemas', 222 226 }, 223 227 '@hey-api/sdk': { 224 - _handler: () => {}, 225 - _handlerLegacy: () => {}, 226 228 config: { 227 229 asClass: true, 228 230 }, 231 + handler: () => {}, 232 + handlerLegacy: () => {}, 229 233 name: '@hey-api/sdk', 230 234 }, 231 235 '@hey-api/typescript': { 232 - _handler: () => {}, 233 - _handlerLegacy: () => {}, 234 236 config: {}, 237 + handler: () => {}, 238 + handlerLegacy: () => {}, 235 239 name: '@hey-api/typescript', 236 240 }, 237 241 'legacy/fetch': { 238 - _handler: () => {}, 239 - _handlerLegacy: () => {}, 240 - _tags: ['client'], 241 242 config: {}, 243 + handler: () => {}, 244 + handlerLegacy: () => {}, 242 245 name: 'legacy/fetch', 246 + tags: ['client'], 243 247 }, 244 248 }, 245 249 useOptions: false, ··· 257 261 client, 258 262 files, 259 263 openApi, 260 - plugin: { 264 + plugin: new PluginInstance({ 261 265 config: { 262 266 exportFromIndex: false, 263 267 }, 268 + context: {} as any, 269 + dependencies: [], 270 + handler: () => {}, 264 271 name: '@hey-api/sdk', 265 272 output: '', 266 - }, 273 + }), 267 274 }); 268 275 269 276 files.sdk!.write(); ··· 307 314 ], 308 315 plugins: { 309 316 '@hey-api/schemas': { 310 - _handler: () => {}, 311 - _handlerLegacy: () => {}, 312 317 config: {}, 318 + handler: () => {}, 319 + handlerLegacy: () => {}, 313 320 name: '@hey-api/schemas', 314 321 }, 315 322 '@hey-api/sdk': { 316 - _handler: () => {}, 317 - _handlerLegacy: () => {}, 318 323 config: { 319 324 asClass: true, 320 325 methodNameBuilder, 321 326 }, 327 + handler: () => {}, 328 + handlerLegacy: () => {}, 322 329 name: '@hey-api/sdk', 323 330 }, 324 331 '@hey-api/typescript': { 325 - _handler: () => {}, 326 - _handlerLegacy: () => {}, 327 332 config: {}, 333 + handler: () => {}, 334 + handlerLegacy: () => {}, 328 335 name: '@hey-api/typescript', 329 336 }, 330 337 'legacy/fetch': { 331 - _handler: () => {}, 332 - _handlerLegacy: () => {}, 333 - _tags: ['client'], 334 338 config: {}, 339 + handler: () => {}, 340 + handlerLegacy: () => {}, 335 341 name: 'legacy/fetch', 342 + tags: ['client'], 336 343 }, 337 344 }, 338 345 useOptions: false, ··· 350 357 client, 351 358 files, 352 359 openApi, 353 - plugin: { 360 + plugin: new PluginInstance({ 354 361 config: { 355 362 exportFromIndex: false, 356 363 }, 364 + context: {} as any, 365 + dependencies: [], 366 + handler: () => {}, 357 367 name: '@hey-api/sdk', 358 368 output: '', 359 - }, 369 + }), 360 370 }); 361 371 362 372 files.sdk!.write(); ··· 402 412 ], 403 413 plugins: { 404 414 '@hey-api/schemas': { 405 - _handler: () => {}, 406 - _handlerLegacy: () => {}, 407 415 config: {}, 416 + handler: () => {}, 417 + handlerLegacy: () => {}, 408 418 name: '@hey-api/schemas', 409 419 }, 410 420 '@hey-api/sdk': { 411 - _handler: () => {}, 412 - _handlerLegacy: () => {}, 413 421 config: { 414 422 asClass: false, 415 423 methodNameBuilder, 416 424 }, 425 + handler: () => {}, 426 + handlerLegacy: () => {}, 417 427 name: '@hey-api/sdk', 418 428 }, 419 429 '@hey-api/typescript': { 420 - _handler: () => {}, 421 - _handlerLegacy: () => {}, 422 430 config: {}, 431 + handler: () => {}, 432 + handlerLegacy: () => {}, 423 433 name: '@hey-api/typescript', 424 434 }, 425 435 'legacy/fetch': { 426 - _handler: () => {}, 427 - _handlerLegacy: () => {}, 428 - _tags: ['client'], 429 436 config: {}, 437 + handler: () => {}, 438 + handlerLegacy: () => {}, 430 439 name: 'legacy/fetch', 440 + tags: ['client'], 431 441 }, 432 442 }, 433 443 useOptions: false, ··· 445 455 client, 446 456 files, 447 457 openApi, 448 - plugin: { 458 + plugin: new PluginInstance({ 449 459 config: { 450 460 exportFromIndex: false, 451 461 }, 462 + context: {} as any, 463 + dependencies: [], 464 + handler: () => {}, 452 465 name: '@hey-api/sdk', 453 466 output: '', 454 - }, 467 + }), 455 468 }); 456 469 457 470 files.sdk!.write();
+23 -24
packages/openapi-ts/src/plugins/@hey-api/sdk/config.ts
··· 5 5 import type { Config } from './types'; 6 6 7 7 export const defaultConfig: Plugin.Config<Config> = { 8 - _dependencies: ['@hey-api/typescript'], 9 - _handler: handler, 10 - _handlerLegacy: handlerLegacy, 11 - _infer: (plugin, context) => { 8 + config: { 9 + asClass: false, 10 + auth: true, 11 + classStructure: 'auto', 12 + client: true, 13 + exportFromIndex: true, 14 + instance: false, 15 + operationId: true, 16 + response: 'body', 17 + responseStyle: 'fields', 18 + }, 19 + dependencies: ['@hey-api/typescript'], 20 + handler, 21 + handlerLegacy, 22 + name: '@hey-api/sdk', 23 + output: 'sdk', 24 + resolveConfig: (plugin, context) => { 12 25 if (plugin.config.client) { 13 26 if (typeof plugin.config.client === 'boolean') { 14 - plugin.config.client = context.pluginByTag({ 27 + plugin.config.client = context.pluginByTag('client', { 15 28 defaultPlugin: '@hey-api/client-fetch', 16 - tag: 'client', 17 29 }); 18 30 } 19 31 20 - context.ensureDependency(plugin.config.client!); 32 + plugin.dependencies.add(plugin.config.client!); 21 33 } 22 34 23 35 if (plugin.config.transformer) { 24 36 if (typeof plugin.config.transformer === 'boolean') { 25 - plugin.config.transformer = context.pluginByTag({ tag: 'transformer' }); 37 + plugin.config.transformer = context.pluginByTag('transformer'); 26 38 } 27 39 28 - context.ensureDependency(plugin.config.transformer!); 40 + plugin.dependencies.add(plugin.config.transformer!); 29 41 } 30 42 31 43 if (plugin.config.validator) { 32 44 if (typeof plugin.config.validator === 'boolean') { 33 - plugin.config.validator = context.pluginByTag({ tag: 'validator' }); 45 + plugin.config.validator = context.pluginByTag('validator'); 34 46 } 35 47 36 - context.ensureDependency(plugin.config.validator!); 48 + plugin.dependencies.add(plugin.config.validator!); 37 49 } 38 50 39 51 if (plugin.config.instance) { ··· 49 61 plugin.config.responseStyle = 'fields'; 50 62 } 51 63 }, 52 - config: { 53 - asClass: false, 54 - auth: true, 55 - classStructure: 'auto', 56 - client: true, 57 - exportFromIndex: true, 58 - instance: false, 59 - operationId: true, 60 - response: 'body', 61 - responseStyle: 'fields', 62 - }, 63 - name: '@hey-api/sdk', 64 - output: 'sdk', 65 64 }; 66 65 67 66 /**
+30 -40
packages/openapi-ts/src/plugins/@hey-api/sdk/plugin.ts
··· 2 2 3 3 import { compiler } from '../../../compiler'; 4 4 import { clientApi, clientModulePath } from '../../../generate/client'; 5 - import type { IR } from '../../../ir/types'; 6 5 import { stringCase } from '../../../utils/stringCase'; 7 6 import { 8 7 createOperationComment, ··· 110 109 root: boolean; 111 110 } 112 111 113 - const generateClassSdk = ({ 114 - context, 115 - plugin, 116 - }: { 117 - context: IR.Context; 118 - plugin: Plugin.Instance<Config>; 119 - }) => { 120 - const client = getClientPlugin(context.config); 112 + const generateClassSdk = ({ plugin }: { plugin: Plugin.Instance<Config> }) => { 113 + const client = getClientPlugin(plugin.context.config); 121 114 const isNuxtClient = client.name === '@hey-api/client-nuxt'; 122 - const file = context.file({ id: sdkId })!; 115 + const file = plugin.context.file({ id: sdkId })!; 123 116 const sdkClasses = new Map<string, SdkClassEntry>(); 124 117 /** 125 118 * Track unique added classes. ··· 130 123 ? createClientClassNodes({ plugin }) 131 124 : []; 132 125 133 - context.subscribe('operation', ({ operation }) => { 126 + plugin.subscribe('operation', ({ operation }) => { 134 127 const isRequiredOptions = isOperationOptionsRequired({ 135 - context, 128 + context: plugin.context, 136 129 operation, 137 130 }); 138 131 const identifierResponse = importIdentifier({ 139 - context, 132 + context: plugin.context, 140 133 file, 141 134 operation, 142 135 type: 'response', 143 136 }); 144 137 145 - const classes = operationClasses({ context, operation, plugin }); 138 + const classes = operationClasses({ 139 + context: plugin.context, 140 + operation, 141 + plugin, 142 + }); 146 143 147 144 for (const entry of classes.values()) { 148 145 entry.path.forEach((currentClassName, index) => { ··· 186 183 isRequired: isRequiredOptions, 187 184 name: 'options', 188 185 type: operationOptionsType({ 189 - context, 186 + context: plugin.context, 190 187 file, 191 188 operation, 192 189 throwOnError: isNuxtClient ? undefined : 'ThrowOnError', ··· 195 192 ], 196 193 returnType: undefined, 197 194 statements: operationStatements({ 198 - context, 195 + context: plugin.context, 199 196 isRequiredOptions, 200 197 operation, 201 198 plugin, ··· 305 302 generatedClasses.add(currentClass.className); 306 303 }; 307 304 308 - context.subscribe('after', () => { 305 + plugin.subscribe('after', () => { 309 306 if (clientClassNodes.length) { 310 307 const node = compiler.classDeclaration({ 311 308 exportClass: false, ··· 321 318 }); 322 319 }; 323 320 324 - const generateFlatSdk = ({ 325 - context, 326 - plugin, 327 - }: { 328 - context: IR.Context; 329 - plugin: Plugin.Instance<Config>; 330 - }) => { 331 - const client = getClientPlugin(context.config); 321 + const generateFlatSdk = ({ plugin }: { plugin: Plugin.Instance<Config> }) => { 322 + const client = getClientPlugin(plugin.context.config); 332 323 const isNuxtClient = client.name === '@hey-api/client-nuxt'; 333 - const file = context.file({ id: sdkId })!; 324 + const file = plugin.context.file({ id: sdkId })!; 334 325 335 - context.subscribe('operation', ({ operation }) => { 326 + plugin.subscribe('operation', ({ operation }) => { 336 327 const isRequiredOptions = isOperationOptionsRequired({ 337 - context, 328 + context: plugin.context, 338 329 operation, 339 330 }); 340 331 const identifierResponse = importIdentifier({ 341 - context, 332 + context: plugin.context, 342 333 file, 343 334 operation, 344 335 type: 'response', ··· 352 343 isRequired: isRequiredOptions, 353 344 name: 'options', 354 345 type: operationOptionsType({ 355 - context, 346 + context: plugin.context, 356 347 file, 357 348 operation, 358 349 throwOnError: isNuxtClient ? undefined : 'ThrowOnError', ··· 361 352 ], 362 353 returnType: undefined, 363 354 statements: operationStatements({ 364 - context, 355 + context: plugin.context, 365 356 isRequiredOptions, 366 357 operation, 367 358 plugin, ··· 399 390 ], 400 391 }), 401 392 name: serviceFunctionIdentifier({ 402 - config: context.config, 393 + config: plugin.context.config, 403 394 handleIllegal: true, 404 395 id: operation.id, 405 396 operation, ··· 409 400 }); 410 401 }; 411 402 412 - export const handler: Plugin.Handler<Config> = ({ context, plugin }) => { 413 - const file = context.createFile({ 414 - exportFromIndex: plugin.config.exportFromIndex, 403 + export const handler: Plugin.Handler<Config> = ({ plugin }) => { 404 + const file = plugin.createFile({ 415 405 id: sdkId, 416 406 path: plugin.output, 417 407 }); 418 408 419 409 // import required packages and core files 420 410 const clientModule = clientModulePath({ 421 - config: context.config, 411 + config: plugin.context.config, 422 412 sourceOutput: file.nameWithoutExtension(), 423 413 }); 424 414 const clientOptions = file.import({ ··· 427 417 module: clientModule, 428 418 }); 429 419 430 - const client = getClientPlugin(context.config); 420 + const client = getClientPlugin(plugin.context.config); 431 421 const isNuxtClient = client.name === '@hey-api/client-nuxt'; 432 422 if (isNuxtClient) { 433 423 file.import({ ··· 439 429 440 430 createTypeOptions({ 441 431 clientOptions, 442 - context, 432 + context: plugin.context, 443 433 plugin, 444 434 }); 445 435 446 436 if (plugin.config.asClass) { 447 - generateClassSdk({ context, plugin }); 437 + generateClassSdk({ plugin }); 448 438 } else { 449 - generateFlatSdk({ context, plugin }); 439 + generateFlatSdk({ plugin }); 450 440 } 451 441 };
+4 -4
packages/openapi-ts/src/plugins/@hey-api/transformers/config.ts
··· 5 5 import type { Config } from './types'; 6 6 7 7 export const defaultConfig: Plugin.Config<Config> = { 8 - _dependencies: ['@hey-api/typescript'], 9 - _handler: handler, 10 - _handlerLegacy: handlerLegacy, 11 - _tags: ['transformer'], 12 8 config: { 13 9 bigInt: true, 14 10 dates: true, 15 11 exportFromIndex: false, 16 12 }, 13 + dependencies: ['@hey-api/typescript'], 14 + handler, 15 + handlerLegacy, 17 16 name: '@hey-api/transformers', 18 17 output: 'transformers', 18 + tags: ['transformer'], 19 19 }; 20 20 21 21 /**
+19 -15
packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts
··· 462 462 }; 463 463 464 464 // handles only response transformers for now 465 - export const handler: Plugin.Handler<Config> = ({ context, plugin }) => { 466 - const file = context.createFile({ 467 - exportFromIndex: plugin.config.exportFromIndex, 465 + export const handler: Plugin.Handler<Config> = ({ plugin }) => { 466 + const file = plugin.createFile({ 468 467 id: transformersId, 469 468 path: plugin.output, 470 469 }); 471 470 472 - context.subscribe('operation', ({ operation }) => { 471 + plugin.subscribe('operation', ({ operation }) => { 473 472 const { response } = operationResponsesMap(operation); 474 473 475 474 if (!response) { ··· 477 476 } 478 477 479 478 if (response.items && response.items.length > 1) { 480 - if (context.config.logs.level === 'debug') { 479 + if (plugin.context.config.logs.level === 'debug') { 481 480 console.warn( 482 481 `❗️ Transformers warning: route ${createOperationKey(operation)} has ${response.items.length} non-void success responses. This is currently not handled and we will not generate a response transformer. Please open an issue if you'd like this feature https://github.com/hey-api/openapi-ts/issues`, 483 482 ); ··· 485 484 return; 486 485 } 487 486 488 - const identifierResponse = context.file({ id: typesId })!.identifier({ 489 - $ref: operationIrRef({ 490 - config: context.config, 491 - id: operation.id, 492 - type: 'response', 493 - }), 494 - namespace: 'type', 495 - }); 487 + const identifierResponse = plugin.context 488 + .file({ id: typesId })! 489 + .identifier({ 490 + $ref: operationIrRef({ 491 + config: plugin.context.config, 492 + id: operation.id, 493 + type: 'response', 494 + }), 495 + namespace: 'type', 496 + }); 496 497 if (!identifierResponse.name) { 497 498 return; 498 499 } ··· 508 509 509 510 // TODO: parser - consider handling simple string response which is also a date 510 511 const nodes = schemaResponseTransformerNodes({ 511 - context, 512 + context: plugin.context, 512 513 plugin, 513 514 schema: response, 514 515 }); 515 516 if (nodes.length) { 516 517 file.import({ 517 518 asType: true, 518 - module: file.relativePathToFile({ context, id: typesId }), 519 + module: file.relativePathToFile({ 520 + context: plugin.context, 521 + id: typesId, 522 + }), 519 523 name: identifierResponse.name, 520 524 }); 521 525 const responseTransformerNode = compiler.constVariable({
+15 -11
packages/openapi-ts/src/plugins/@hey-api/typescript/__tests__/plugin.test.ts
··· 6 6 import { TypeScriptFile } from '../../../../generate/files'; 7 7 import type { Config } from '../../../../types/config'; 8 8 import { setConfig } from '../../../../utils/config'; 9 + import { PluginInstance } from '../../../shared/utils/instance'; 9 10 import { handlerLegacy } from '../plugin-legacy'; 10 11 11 12 vi.mock('node:fs'); ··· 43 44 ], 44 45 plugins: { 45 46 '@hey-api/schemas': { 46 - _handler: () => {}, 47 - _handlerLegacy: () => {}, 48 47 config: {}, 48 + handler: () => {}, 49 + handlerLegacy: () => {}, 49 50 name: '@hey-api/schemas', 50 51 }, 51 52 '@hey-api/sdk': { 52 - _handler: () => {}, 53 - _handlerLegacy: () => {}, 54 53 config: {}, 54 + handler: () => {}, 55 + handlerLegacy: () => {}, 55 56 name: '@hey-api/sdk', 56 57 }, 57 58 '@hey-api/typescript': { 58 - _handler: () => {}, 59 - _handlerLegacy: () => {}, 60 59 config: { 61 60 enums: 'javascript', 62 61 }, 62 + handler: () => {}, 63 + handlerLegacy: () => {}, 63 64 name: '@hey-api/typescript', 64 65 }, 65 66 'legacy/fetch': { 66 - _handler: () => {}, 67 - _handlerLegacy: () => {}, 68 - _tags: ['client'], 69 67 config: {}, 68 + handler: () => {}, 69 + handlerLegacy: () => {}, 70 70 name: 'legacy/fetch', 71 + tags: ['client'], 71 72 }, 72 73 }, 73 74 useOptions: true, ··· 118 119 client, 119 120 files, 120 121 openApi, 121 - plugin: { 122 + plugin: new PluginInstance({ 122 123 config: { 123 124 exportFromIndex: false, 124 125 }, 126 + context: {} as any, 127 + dependencies: [], 128 + handler: () => {}, 125 129 name: '@hey-api/typescript', 126 130 output: '', 127 - }, 131 + }), 128 132 }); 129 133 130 134 files.types.write();
+2 -2
packages/openapi-ts/src/plugins/@hey-api/typescript/config.ts
··· 5 5 import type { Config } from './types'; 6 6 7 7 export const defaultConfig: Plugin.Config<Config> = { 8 - _handler: handler, 9 - _handlerLegacy: handlerLegacy, 10 8 config: { 11 9 enums: false, 12 10 enumsCase: 'SCREAMING_SNAKE_CASE', ··· 20 18 tree: false, 21 19 writableNameBuilder: '{{name}}Writable', 22 20 }, 21 + handler, 22 + handlerLegacy, 23 23 name: '@hey-api/typescript', 24 24 output: 'types', 25 25 };
+23 -24
packages/openapi-ts/src/plugins/@hey-api/typescript/plugin.ts
··· 524 524 }; 525 525 526 526 const numberTypeToIdentifier = ({ 527 - context, 527 + plugin, 528 528 schema, 529 529 }: { 530 - context: IR.Context; 531 530 namespace: Array<ts.Statement>; 531 + plugin: Plugin.Instance<Config>; 532 532 schema: SchemaWithType<'integer' | 'number'>; 533 533 }): ts.TypeNode => { 534 534 if (schema.const !== undefined) { ··· 539 539 540 540 if (schema.type === 'integer' && schema.format === 'int64') { 541 541 // TODO: parser - add ability to skip type transformers 542 - if (context.config.plugins['@hey-api/transformers']?.config.bigInt) { 542 + if (plugin.getPlugin('@hey-api/transformers')?.config.bigInt) { 543 543 return compiler.typeReferenceNode({ typeName: 'bigint' }); 544 544 } 545 545 } ··· 666 666 }; 667 667 668 668 const stringTypeToIdentifier = ({ 669 - context, 669 + plugin, 670 670 schema, 671 671 }: { 672 - context: IR.Context; 673 672 namespace: Array<ts.Statement>; 673 + plugin: Plugin.Instance<Config>; 674 674 schema: SchemaWithType<'string'>; 675 675 }): ts.TypeNode => { 676 676 if (schema.const !== undefined) { ··· 695 695 696 696 if (schema.format === 'date-time' || schema.format === 'date') { 697 697 // TODO: parser - add ability to skip type transformers 698 - if (context.config.plugins['@hey-api/transformers']?.config.dates) { 698 + if (plugin.getPlugin('@hey-api/transformers')?.config.dates) { 699 699 return compiler.typeReferenceNode({ typeName: 'Date' }); 700 700 } 701 701 } ··· 793 793 case 'integer': 794 794 case 'number': 795 795 return numberTypeToIdentifier({ 796 - context, 797 796 namespace, 797 + plugin, 798 798 schema: schema as SchemaWithType<'integer' | 'number'>, 799 799 }); 800 800 case 'never': ··· 815 815 }); 816 816 case 'string': 817 817 return stringTypeToIdentifier({ 818 - context, 819 818 namespace, 819 + plugin, 820 820 schema: schema as SchemaWithType<'string'>, 821 821 }); 822 822 case 'tuple': ··· 1314 1314 return type; 1315 1315 }; 1316 1316 1317 - export const handler: Plugin.Handler<Config> = ({ context, plugin }) => { 1318 - const file = context.createFile({ 1319 - exportFromIndex: plugin.config.exportFromIndex, 1317 + export const handler: Plugin.Handler<Config> = ({ plugin }) => { 1318 + const file = plugin.createFile({ 1320 1319 id: typesId, 1321 1320 identifierCase: plugin.config.identifierCase, 1322 1321 path: plugin.output, ··· 1329 1328 namespace: 'type', 1330 1329 }); 1331 1330 1332 - context.subscribe('schema', ({ $ref, schema }) => { 1331 + plugin.subscribe('schema', ({ $ref, schema }) => { 1333 1332 if ( 1334 1333 plugin.config.readOnlyWriteOnlyBehavior === 'off' || 1335 1334 !isSchemaSplit({ schema }) 1336 1335 ) { 1337 1336 schemaToType({ 1338 1337 $ref, 1339 - context, 1338 + context: plugin.context, 1340 1339 plugin, 1341 1340 schema, 1342 1341 state: { ··· 1354 1353 accessScope: 'read', 1355 1354 plugin, 1356 1355 }), 1357 - context, 1356 + context: plugin.context, 1358 1357 plugin, 1359 1358 schema, 1360 1359 state: { ··· 1372 1371 accessScope: 'write', 1373 1372 plugin, 1374 1373 }), 1375 - context, 1374 + context: plugin.context, 1376 1375 plugin, 1377 1376 schema, 1378 1377 state: { ··· 1384 1383 } 1385 1384 }); 1386 1385 1387 - context.subscribe('parameter', ({ $ref, parameter }) => { 1386 + plugin.subscribe('parameter', ({ $ref, parameter }) => { 1388 1387 schemaToType({ 1389 1388 $ref, 1390 - context, 1389 + context: plugin.context, 1391 1390 plugin, 1392 1391 schema: parameter.schema, 1393 1392 state: { ··· 1397 1396 }); 1398 1397 }); 1399 1398 1400 - context.subscribe('requestBody', ({ $ref, requestBody }) => { 1399 + plugin.subscribe('requestBody', ({ $ref, requestBody }) => { 1401 1400 schemaToType({ 1402 1401 $ref, 1403 - context, 1402 + context: plugin.context, 1404 1403 plugin, 1405 1404 schema: requestBody.schema, 1406 1405 state: ··· 1417 1416 }); 1418 1417 }); 1419 1418 1420 - context.subscribe('operation', ({ operation }) => { 1419 + plugin.subscribe('operation', ({ operation }) => { 1421 1420 operationToType({ 1422 - context, 1421 + context: plugin.context, 1423 1422 operation, 1424 1423 plugin, 1425 1424 }); ··· 1427 1426 1428 1427 const servers: Array<IR.ServerObject> = []; 1429 1428 1430 - context.subscribe('server', ({ server }) => { 1429 + plugin.subscribe('server', ({ server }) => { 1431 1430 servers.push(server); 1432 1431 }); 1433 1432 1434 - context.subscribe('after', () => { 1433 + plugin.subscribe('after', () => { 1435 1434 createClientOptions({ 1436 - context, 1435 + context: plugin.context, 1437 1436 identifier: clientOptions, 1438 1437 plugin, 1439 1438 servers,
+4 -6
packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/config.ts
··· 6 6 import type { Config } from './types'; 7 7 8 8 export const defaultConfig: Plugin.Config<Config> = { 9 - _dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 10 - _handler: handler, 11 - _handlerLegacy: handlerLegacy, 12 - config: { 13 - ...defaultTanStackQueryConfig, 14 - }, 9 + config: defaultTanStackQueryConfig, 10 + dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 11 + handler, 12 + handlerLegacy, 15 13 name: '@tanstack/angular-query-experimental', 16 14 output: '@tanstack/angular-query-experimental', 17 15 };
+3 -4
packages/openapi-ts/src/plugins/@tanstack/query-core/infiniteQueryOptions.ts
··· 314 314 315 315 const typeQueryKey = `${queryKeyName}<${typeData}>`; 316 316 const typePageObjectParam = `Pick<${typeQueryKey}[0], 'body' | 'headers' | 'path' | 'query'>`; 317 + const pluginTypeScript = plugin.getPlugin('@hey-api/typescript'); 317 318 // TODO: parser - this is a bit clunky, need to compile type to string because 318 319 // `compiler.returnFunctionCall()` accepts only strings, should be cleaned up 319 320 const type = schemaToType({ 320 321 context, 321 - plugin: context.config.plugins['@hey-api/typescript'] as Parameters< 322 - typeof schemaToType 323 - >[0]['plugin'], 322 + plugin: pluginTypeScript as Parameters<typeof schemaToType>[0]['plugin'], 324 323 schema: pagination.schema, 325 324 state: undefined, 326 325 }); ··· 431 430 }), 432 431 ]; 433 432 434 - if (context.config.plugins['@hey-api/sdk']?.config.responseStyle === 'data') { 433 + if (plugin.getPlugin('@hey-api/sdk')?.config.responseStyle === 'data') { 435 434 statements.push( 436 435 compiler.returnVariable({ 437 436 expression: awaitSdkExpression,
+1 -1
packages/openapi-ts/src/plugins/@tanstack/query-core/mutationOptions.ts
··· 114 114 115 115 const statements: Array<ts.Statement> = []; 116 116 117 - if (context.config.plugins['@hey-api/sdk']?.config.responseStyle === 'data') { 117 + if (plugin.getPlugin('@hey-api/sdk')?.config.responseStyle === 'data') { 118 118 statements.push( 119 119 compiler.returnVariable({ 120 120 expression: awaitSdkExpression,
+22 -16
packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts
··· 9 9 import { createQueryOptions } from './queryOptions'; 10 10 import type { PluginHandler, PluginState } from './types'; 11 11 12 - export const handler: PluginHandler = ({ context, plugin }) => { 13 - const file = context.createFile({ 14 - exportFromIndex: plugin.config.exportFromIndex, 12 + export const handler: PluginHandler = ({ plugin }) => { 13 + const file = plugin.createFile({ 15 14 id: plugin.name, 16 15 path: plugin.output, 17 16 }); ··· 26 25 typeInfiniteData: undefined!, 27 26 }; 28 27 29 - context.subscribe('before', () => { 28 + plugin.subscribe('before', () => { 30 29 file.import({ 31 30 ...clientApi.Options, 32 - module: file.relativePathToFile({ context, id: sdkId }), 31 + module: file.relativePathToFile({ context: plugin.context, id: sdkId }), 33 32 }); 34 33 }); 35 34 36 - context.subscribe('operation', ({ operation }) => { 35 + plugin.subscribe('operation', ({ operation }) => { 37 36 state.hasUsedQueryFn = false; 38 37 39 - const sdk = context.config.plugins['@hey-api/sdk']; 40 - const classes = sdk?.config.asClass 41 - ? operationClasses({ context, operation, plugin: sdk }) 38 + const sdkPlugin = plugin.getPlugin('@hey-api/sdk'); 39 + const classes = sdkPlugin?.config.asClass 40 + ? operationClasses({ 41 + context: plugin.context, 42 + operation, 43 + plugin: sdkPlugin, 44 + }) 42 45 : undefined; 43 46 const entry = classes ? classes.values().next().value : undefined; 44 47 const queryFn = ··· 58 61 ].filter(Boolean) 59 62 : [ 60 63 serviceFunctionIdentifier({ 61 - config: context.config, 64 + config: plugin.context.config, 62 65 handleIllegal: true, 63 66 id: operation.id, 64 67 operation, ··· 67 70 ).join('.'); 68 71 69 72 createQueryOptions({ 70 - context, 73 + context: plugin.context, 71 74 operation, 72 75 plugin, 73 76 queryFn, ··· 75 78 }); 76 79 77 80 createInfiniteQueryOptions({ 78 - context, 81 + context: plugin.context, 79 82 operation, 80 83 plugin, 81 84 queryFn, ··· 83 86 }); 84 87 85 88 createMutationOptions({ 86 - context, 89 + context: plugin.context, 87 90 operation, 88 91 plugin, 89 92 queryFn, ··· 92 95 93 96 if (state.hasUsedQueryFn) { 94 97 file.import({ 95 - module: file.relativePathToFile({ context, id: sdkId }), 98 + module: file.relativePathToFile({ context: plugin.context, id: sdkId }), 96 99 name: queryFn.split('.')[0]!, 97 100 }); 98 101 } 99 102 }); 100 103 101 - context.subscribe('after', () => { 104 + plugin.subscribe('after', () => { 102 105 if (state.hasQueries || state.hasInfiniteQueries) { 103 106 file.import({ 104 107 alias: '_heyApiClient', 105 - module: file.relativePathToFile({ context, id: clientId }), 108 + module: file.relativePathToFile({ 109 + context: plugin.context, 110 + id: clientId, 111 + }), 106 112 name: 'client', 107 113 }); 108 114 }
+1 -1
packages/openapi-ts/src/plugins/@tanstack/query-core/queryOptions.ts
··· 141 141 142 142 const statements: Array<ts.Statement> = []; 143 143 144 - if (context.config.plugins['@hey-api/sdk']?.config.responseStyle === 'data') { 144 + if (plugin.getPlugin('@hey-api/sdk')?.config.responseStyle === 'data') { 145 145 statements.push( 146 146 compiler.returnVariable({ 147 147 expression: awaitSdkExpression,
+1 -1
packages/openapi-ts/src/plugins/@tanstack/query-core/types.d.ts
··· 7 7 import type { Config as VueQueryConfig } from '../vue-query'; 8 8 9 9 export type PluginHandler = Plugin.Handler< 10 - | ReactQueryConfig 11 10 | AngularQueryConfig 11 + | ReactQueryConfig 12 12 | SolidQueryConfig 13 13 | SvelteQueryConfig 14 14 | VueQueryConfig
+4 -6
packages/openapi-ts/src/plugins/@tanstack/react-query/config.ts
··· 6 6 import type { Config } from './types'; 7 7 8 8 export const defaultConfig: Plugin.Config<Config> = { 9 - _dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 10 - _handler: handler, 11 - _handlerLegacy: handlerLegacy, 12 - config: { 13 - ...defaultTanStackQueryConfig, 14 - }, 9 + config: defaultTanStackQueryConfig, 10 + dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 11 + handler, 12 + handlerLegacy, 15 13 name: '@tanstack/react-query', 16 14 output: '@tanstack/react-query', 17 15 };
+4 -6
packages/openapi-ts/src/plugins/@tanstack/solid-query/config.ts
··· 6 6 import type { Config } from './types'; 7 7 8 8 export const defaultConfig: Plugin.Config<Config> = { 9 - _dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 10 - _handler: handler, 11 - _handlerLegacy: handlerLegacy, 12 - config: { 13 - ...defaultTanStackQueryConfig, 14 - }, 9 + config: defaultTanStackQueryConfig, 10 + dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 11 + handler, 12 + handlerLegacy, 15 13 name: '@tanstack/solid-query', 16 14 output: '@tanstack/solid-query', 17 15 };
+4 -6
packages/openapi-ts/src/plugins/@tanstack/svelte-query/config.ts
··· 6 6 import type { Config } from './types'; 7 7 8 8 export const defaultConfig: Plugin.Config<Config> = { 9 - _dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 10 - _handler: handler, 11 - _handlerLegacy: handlerLegacy, 12 - config: { 13 - ...defaultTanStackQueryConfig, 14 - }, 9 + config: defaultTanStackQueryConfig, 10 + dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 11 + handler, 12 + handlerLegacy, 15 13 name: '@tanstack/svelte-query', 16 14 output: '@tanstack/svelte-query', 17 15 };
+4 -6
packages/openapi-ts/src/plugins/@tanstack/vue-query/config.ts
··· 6 6 import type { Config } from './types'; 7 7 8 8 export const defaultConfig: Plugin.Config<Config> = { 9 - _dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 10 - _handler: handler, 11 - _handlerLegacy: handlerLegacy, 12 - config: { 13 - ...defaultTanStackQueryConfig, 14 - }, 9 + config: defaultTanStackQueryConfig, 10 + dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 11 + handler, 12 + handlerLegacy, 15 13 name: '@tanstack/vue-query', 16 14 output: '@tanstack/vue-query', 17 15 };
+3 -3
packages/openapi-ts/src/plugins/fastify/config.ts
··· 4 4 import type { Config } from './types'; 5 5 6 6 export const defaultConfig: Plugin.Config<Config> = { 7 - _dependencies: ['@hey-api/typescript'], 8 - _handler: handler, 9 - _handlerLegacy: () => {}, 10 7 config: { 11 8 exportFromIndex: false, 12 9 }, 10 + dependencies: ['@hey-api/typescript'], 11 + handler, 12 + handlerLegacy: () => {}, 13 13 name: 'fastify', 14 14 output: 'fastify', 15 15 };
+8 -6
packages/openapi-ts/src/plugins/fastify/plugin.ts
··· 207 207 return routeHandler; 208 208 }; 209 209 210 - export const handler: Plugin.Handler<Config> = ({ context, plugin }) => { 211 - const file = context.createFile({ 212 - exportFromIndex: plugin.config.exportFromIndex, 210 + export const handler: Plugin.Handler<Config> = ({ plugin }) => { 211 + const file = plugin.createFile({ 213 212 id: fastifyId, 214 213 path: plugin.output, 215 214 }); 216 215 217 216 const routeHandlers: Array<Property> = []; 218 217 219 - context.subscribe('operation', ({ operation }) => { 220 - const routeHandler = operationToRouteHandler({ context, operation }); 218 + plugin.subscribe('operation', ({ operation }) => { 219 + const routeHandler = operationToRouteHandler({ 220 + context: plugin.context, 221 + operation, 222 + }); 221 223 if (routeHandler) { 222 224 routeHandlers.push(routeHandler); 223 225 } 224 226 }); 225 227 226 - context.subscribe('after', () => { 228 + plugin.subscribe('after', () => { 227 229 const identifier = file.identifier({ 228 230 $ref: 'RouteHandlers', 229 231 create: true,
+74
packages/openapi-ts/src/plugins/shared/utils/instance.ts
··· 1 + import type { IR } from '../../../ir/types'; 2 + import type { OpenApi } from '../../../openApi/types'; 3 + import type { Config } from '../../../types/config'; 4 + import type { BaseConfig, Plugin } from '../../types'; 5 + 6 + export class PluginInstance<PluginConfig extends BaseConfig = BaseConfig> { 7 + public config: Plugin.Config<PluginConfig>['config']; 8 + public context: IR.Context; 9 + public dependencies: Required<Plugin.Config<PluginConfig>>['dependencies'] = 10 + []; 11 + private handler: Plugin.Config<PluginConfig>['handler']; 12 + public name: Plugin.Config<PluginConfig>['name']; 13 + public output: Required<PluginConfig>['output']; 14 + 15 + public constructor( 16 + props: Pick< 17 + Required<Plugin.Config<PluginConfig>>, 18 + 'config' | 'dependencies' | 'handler' 19 + > & 20 + Pick<Required<PluginConfig>, 'output'> & { 21 + context: IR.Context<OpenApi.V2_0_X | OpenApi.V3_0_X | OpenApi.V3_1_X>; 22 + name: string; 23 + }, 24 + ) { 25 + this.config = props.config; 26 + this.context = props.context; 27 + this.dependencies = props.dependencies; 28 + this.handler = props.handler; 29 + this.name = props.name; 30 + this.output = props.output; 31 + } 32 + 33 + public createFile(file: IR.ContextFile) { 34 + return this.context.createFile({ 35 + exportFromIndex: this.config.exportFromIndex, 36 + ...file, 37 + }); 38 + } 39 + 40 + /** 41 + * Retrieves a registered plugin instance by its name from the context. This 42 + * allows plugins to access other plugins that have been registered in the 43 + * same context, enabling cross-plugin communication and dependencies. 44 + * 45 + * @param name Plugin name as defined in the configuration. 46 + * @returns The plugin instance if found, undefined otherwise. 47 + */ 48 + public getPlugin<T extends keyof Config['plugins']>( 49 + name: T, 50 + ): IR.Context['plugins'][T] { 51 + return this.context.plugins[name]; 52 + } 53 + 54 + /** 55 + * Executes plugin's handler function. 56 + */ 57 + public async run() { 58 + await this.handler({ plugin: this }); 59 + } 60 + 61 + /** 62 + * Subscribe to an input parser event. 63 + * 64 + * @param event Event type from the parser. 65 + * @param callbackFn Function to execute on event. 66 + * @returns void 67 + */ 68 + public subscribe<T extends keyof IR.ContextEvents>( 69 + event: T, 70 + callbackFn: IR.ContextEvents[T], 71 + ) { 72 + return this.context.subscribe(event, callbackFn, this.name); 73 + } 74 + }
+30 -25
packages/openapi-ts/src/plugins/types.d.ts
··· 1 - import type { IR } from '../ir/types'; 2 1 import type { OpenApi as LegacyOpenApi } from '../openApi'; 3 - import type { OpenApi } from '../openApi/types'; 4 2 import type { Client as LegacyClient } from '../types/client'; 5 3 import type { Files } from '../types/utils'; 6 - 7 - type OmitUnderscoreKeys<T> = { 8 - [K in keyof T as K extends `_${string}` ? never : K]: T[K]; 9 - }; 4 + import type { PluginInstance } from './shared/utils/instance'; 10 5 11 6 export type PluginClientNames = 12 7 | '@hey-api/client-axios' ··· 40 35 type PluginTag = 'client' | 'transformer' | 'validator'; 41 36 42 37 export interface PluginContext { 43 - ensureDependency: (name: PluginNames) => void; 44 - pluginByTag: <T extends AnyPluginName | boolean = AnyPluginName>(props: { 45 - defaultPlugin?: Exclude<T, boolean>; 46 - errorMessage?: string; 47 - tag: PluginTag; 48 - }) => Exclude<T, boolean> | undefined; 38 + pluginByTag: <T extends AnyPluginName | boolean = AnyPluginName>( 39 + tag: PluginTag, 40 + props?: { 41 + defaultPlugin?: Exclude<T, boolean>; 42 + errorMessage?: string; 43 + }, 44 + ) => Exclude<T, boolean> | undefined; 49 45 } 50 46 51 47 export interface BaseConfig { ··· 63 59 * Dependency plugins will be always processed, regardless of whether user 64 60 * explicitly defines them in their `plugins` config. 65 61 */ 66 - _dependencies?: ReadonlyArray<AnyPluginName>; 62 + dependencies?: ReadonlyArray<AnyPluginName>; 67 63 /** 68 - * Allows overriding config before it's sent to the parser. An example is 69 - * defining `validator` as `true` and the plugin figures out which plugin 64 + * Resolves static configuration values into their runtime equivalents. For 65 + * example, when `validator` is set to `true`, it figures out which plugin 70 66 * should be used for validation. 71 67 */ 72 - _infer?: (config: Plugin.Config<Config>, context: PluginContext) => void; 68 + resolveConfig?: ( 69 + config: Omit<Plugin.Config<Config>, 'dependencies'> & { 70 + dependencies: Set<AnyPluginName>; 71 + }, 72 + context: PluginContext, 73 + ) => void; 73 74 /** 74 - * Optional tags can be used to help with deciding plugin order and inferring 75 + * Optional tags can be used to help with deciding plugin order and resolving 75 76 * plugin configuration options. 76 77 */ 77 - _tags?: ReadonlyArray<PluginTag>; 78 + tags?: ReadonlyArray<PluginTag>; 78 79 } 79 80 80 81 /** ··· 86 87 'name' | 'output' 87 88 > & 88 89 Meta<Config> & { 89 - _handler: Plugin.Handler<Config>; 90 - _handlerLegacy: Plugin.LegacyHandler<Config>; 91 90 config: Omit<Config, 'name' | 'output'>; 91 + handler: Plugin.Handler< 92 + Omit<Config, 'name'> & { 93 + name: any; 94 + } 95 + >; 96 + handlerLegacy: Plugin.LegacyHandler< 97 + Omit<Config, 'name'> & { 98 + name: any; 99 + } 100 + >; 92 101 }; 93 102 94 103 /** @deprecated - use `definePluginConfig()` instead */ ··· 108 117 * Plugin implementation for experimental parser. 109 118 */ 110 119 export type Handler<Config extends BaseConfig, ReturnType = void> = (args: { 111 - context: IR.Context<OpenApi.V2_0_X | OpenApi.V3_0_X | OpenApi.V3_1_X>; 112 120 plugin: Plugin.Instance<Config>; 113 121 }) => ReturnType; 114 122 115 - export type Instance<Config extends BaseConfig> = OmitUnderscoreKeys< 116 - Plugin.Config<Config> 117 - > & 118 - Pick<Required<BaseConfig>, 'name' | 'output'>; 123 + export type Instance<Config extends BaseConfig> = PluginInstance<Config>; 119 124 120 125 /** 121 126 * Plugin implementation for legacy parser.
+3 -3
packages/openapi-ts/src/plugins/valibot/config.ts
··· 4 4 import type { Config } from './types'; 5 5 6 6 export const defaultConfig: Plugin.Config<Config> = { 7 - _handler: handler, 8 - _handlerLegacy: () => {}, 9 - _tags: ['validator'], 10 7 config: { 11 8 comments: true, 12 9 exportFromIndex: false, 13 10 }, 11 + handler, 12 + handlerLegacy: () => {}, 14 13 name: 'valibot', 15 14 output: 'valibot', 15 + tags: ['validator'], 16 16 }; 17 17 18 18 /**
+10 -11
packages/openapi-ts/src/plugins/valibot/plugin.ts
··· 1162 1162 return pipes; 1163 1163 }; 1164 1164 1165 - export const handler: Plugin.Handler<Config> = ({ context, plugin }) => { 1166 - const file = context.createFile({ 1167 - exportFromIndex: plugin.config.exportFromIndex, 1165 + export const handler: Plugin.Handler<Config> = ({ plugin }) => { 1166 + const file = plugin.createFile({ 1168 1167 id: valibotId, 1169 1168 identifierCase: 'camelCase', 1170 1169 path: plugin.output, ··· 1176 1175 name: '*', 1177 1176 }); 1178 1177 1179 - context.subscribe('operation', ({ operation }) => { 1178 + plugin.subscribe('operation', ({ operation }) => { 1180 1179 const result: Result = { 1181 1180 circularReferenceTracker: new Set(), 1182 1181 hasCircularReference: false, 1183 1182 }; 1184 1183 1185 1184 operationToValibotSchema({ 1186 - context, 1185 + context: plugin.context, 1187 1186 operation, 1188 1187 plugin, 1189 1188 result, 1190 1189 }); 1191 1190 }); 1192 1191 1193 - context.subscribe('parameter', ({ $ref, parameter }) => { 1192 + plugin.subscribe('parameter', ({ $ref, parameter }) => { 1194 1193 const result: Result = { 1195 1194 circularReferenceTracker: new Set(), 1196 1195 hasCircularReference: false, ··· 1198 1197 1199 1198 schemaToValibotSchema({ 1200 1199 $ref, 1201 - context, 1200 + context: plugin.context, 1202 1201 plugin, 1203 1202 result, 1204 1203 schema: parameter.schema, 1205 1204 }); 1206 1205 }); 1207 1206 1208 - context.subscribe('requestBody', ({ $ref, requestBody }) => { 1207 + plugin.subscribe('requestBody', ({ $ref, requestBody }) => { 1209 1208 const result: Result = { 1210 1209 circularReferenceTracker: new Set(), 1211 1210 hasCircularReference: false, ··· 1213 1212 1214 1213 schemaToValibotSchema({ 1215 1214 $ref, 1216 - context, 1215 + context: plugin.context, 1217 1216 plugin, 1218 1217 result, 1219 1218 schema: requestBody.schema, 1220 1219 }); 1221 1220 }); 1222 1221 1223 - context.subscribe('schema', ({ $ref, schema }) => { 1222 + plugin.subscribe('schema', ({ $ref, schema }) => { 1224 1223 const result: Result = { 1225 1224 circularReferenceTracker: new Set(), 1226 1225 hasCircularReference: false, ··· 1228 1227 1229 1228 schemaToValibotSchema({ 1230 1229 $ref, 1231 - context, 1230 + context: plugin.context, 1232 1231 plugin, 1233 1232 result, 1234 1233 schema,
+3 -3
packages/openapi-ts/src/plugins/zod/config.ts
··· 4 4 import type { Config } from './types'; 5 5 6 6 export const defaultConfig: Plugin.Config<Config> = { 7 - _handler: handler, 8 - _handlerLegacy: () => {}, 9 - _tags: ['validator'], 10 7 config: { 11 8 comments: true, 12 9 exportFromIndex: false, 13 10 metadata: false, 14 11 }, 12 + handler, 13 + handlerLegacy: () => {}, 15 14 name: 'zod', 16 15 output: 'zod', 16 + tags: ['validator'], 17 17 }; 18 18 19 19 /**
+10 -11
packages/openapi-ts/src/plugins/zod/plugin.ts
··· 1145 1145 return expression!; 1146 1146 }; 1147 1147 1148 - export const handler: Plugin.Handler<Config> = ({ context, plugin }) => { 1149 - const file = context.createFile({ 1150 - exportFromIndex: plugin.config.exportFromIndex, 1148 + export const handler: Plugin.Handler<Config> = ({ plugin }) => { 1149 + const file = plugin.createFile({ 1151 1150 id: zodId, 1152 1151 identifierCase: 'camelCase', 1153 1152 path: plugin.output, ··· 1158 1157 name: 'z', 1159 1158 }); 1160 1159 1161 - context.subscribe('operation', ({ operation }) => { 1160 + plugin.subscribe('operation', ({ operation }) => { 1162 1161 const result: Result = { 1163 1162 circularReferenceTracker: new Set(), 1164 1163 hasCircularReference: false, 1165 1164 }; 1166 1165 1167 1166 operationToZodSchema({ 1168 - context, 1167 + context: plugin.context, 1169 1168 operation, 1170 1169 plugin, 1171 1170 result, 1172 1171 }); 1173 1172 }); 1174 1173 1175 - context.subscribe('parameter', ({ $ref, parameter }) => { 1174 + plugin.subscribe('parameter', ({ $ref, parameter }) => { 1176 1175 const result: Result = { 1177 1176 circularReferenceTracker: new Set(), 1178 1177 hasCircularReference: false, ··· 1180 1179 1181 1180 schemaToZodSchema({ 1182 1181 $ref, 1183 - context, 1182 + context: plugin.context, 1184 1183 plugin, 1185 1184 result, 1186 1185 schema: parameter.schema, 1187 1186 }); 1188 1187 }); 1189 1188 1190 - context.subscribe('requestBody', ({ $ref, requestBody }) => { 1189 + plugin.subscribe('requestBody', ({ $ref, requestBody }) => { 1191 1190 const result: Result = { 1192 1191 circularReferenceTracker: new Set(), 1193 1192 hasCircularReference: false, ··· 1195 1194 1196 1195 schemaToZodSchema({ 1197 1196 $ref, 1198 - context, 1197 + context: plugin.context, 1199 1198 plugin, 1200 1199 result, 1201 1200 schema: requestBody.schema, 1202 1201 }); 1203 1202 }); 1204 1203 1205 - context.subscribe('schema', ({ $ref, schema }) => { 1204 + plugin.subscribe('schema', ({ $ref, schema }) => { 1206 1205 const result: Result = { 1207 1206 circularReferenceTracker: new Set(), 1208 1207 hasCircularReference: false, ··· 1210 1209 1211 1210 schemaToZodSchema({ 1212 1211 $ref, 1213 - context, 1212 + context: plugin.context, 1214 1213 plugin, 1215 1214 result, 1216 1215 schema,
+18 -18
packages/openapi-ts/src/utils/__tests__/handlebars.test.ts
··· 40 40 ], 41 41 plugins: { 42 42 '@hey-api/schemas': { 43 - _handler: () => {}, 44 - _handlerLegacy: () => {}, 45 43 config: {}, 44 + handler: () => {}, 45 + handlerLegacy: () => {}, 46 46 name: '@hey-api/schemas', 47 47 }, 48 48 '@hey-api/sdk': { 49 - _handler: () => {}, 50 - _handlerLegacy: () => {}, 51 49 config: {}, 50 + handler: () => {}, 51 + handlerLegacy: () => {}, 52 52 name: '@hey-api/sdk', 53 53 }, 54 54 '@hey-api/typescript': { 55 - _handler: () => {}, 56 - _handlerLegacy: () => {}, 57 55 config: { 58 56 enums: 'javascript', 59 57 }, 58 + handler: () => {}, 59 + handlerLegacy: () => {}, 60 60 name: '@hey-api/typescript', 61 61 }, 62 62 'legacy/fetch': { 63 - _handler: () => {}, 64 - _handlerLegacy: () => {}, 65 - _tags: ['client'], 66 63 config: {}, 64 + handler: () => {}, 65 + handlerLegacy: () => {}, 67 66 name: 'legacy/fetch', 67 + tags: ['client'], 68 68 }, 69 69 }, 70 70 useOptions: false, ··· 113 113 ], 114 114 plugins: { 115 115 '@hey-api/schemas': { 116 - _handler: () => {}, 117 - _handlerLegacy: () => {}, 118 116 config: {}, 117 + handler: () => {}, 118 + handlerLegacy: () => {}, 119 119 name: '@hey-api/schemas', 120 120 }, 121 121 '@hey-api/sdk': { 122 - _handler: () => {}, 123 - _handlerLegacy: () => {}, 124 122 config: {}, 123 + handler: () => {}, 124 + handlerLegacy: () => {}, 125 125 name: '@hey-api/sdk', 126 126 }, 127 127 '@hey-api/typescript': { 128 - _handler: () => {}, 129 - _handlerLegacy: () => {}, 130 128 config: { 131 129 enums: 'javascript', 132 130 }, 131 + handler: () => {}, 132 + handlerLegacy: () => {}, 133 133 name: '@hey-api/typescript', 134 134 }, 135 135 'legacy/fetch': { 136 - _handler: () => {}, 137 - _handlerLegacy: () => {}, 138 - _tags: ['client'], 139 136 config: {}, 137 + handler: () => {}, 138 + handlerLegacy: () => {}, 140 139 name: 'legacy/fetch', 140 + tags: ['client'], 141 141 }, 142 142 }, 143 143 useOptions: false,
+19 -19
packages/openapi-ts/src/utils/__tests__/parse.test.ts
··· 29 29 pluginOrder: ['legacy/fetch', '@hey-api/sdk'], 30 30 plugins: { 31 31 '@hey-api/sdk': { 32 - _handler: () => {}, 33 - _handlerLegacy: () => {}, 34 32 config: { 35 33 operationId: true, 36 34 response: 'body', 37 35 }, 36 + handler: () => {}, 37 + handlerLegacy: () => {}, 38 38 name: '@hey-api/sdk', 39 39 }, 40 40 'legacy/fetch': { 41 - _handler: () => {}, 42 - _handlerLegacy: () => {}, 43 - _tags: ['client'], 44 41 config: {}, 42 + handler: () => {}, 43 + handlerLegacy: () => {}, 45 44 name: 'legacy/fetch', 45 + tags: ['client'], 46 46 }, 47 47 }, 48 48 useOptions: false, ··· 53 53 plugins: { 54 54 ...optionsCommon.plugins, 55 55 '@hey-api/sdk': { 56 - _handler: () => {}, 57 - _handlerLegacy: () => {}, 58 56 config: { 59 57 operationId: true, 60 58 response: 'body', 61 59 }, 60 + handler: () => {}, 61 + handlerLegacy: () => {}, 62 62 name: '@hey-api/sdk', 63 63 }, 64 64 }, ··· 69 69 plugins: { 70 70 ...optionsCommon.plugins, 71 71 '@hey-api/sdk': { 72 - _handler: () => {}, 73 - _handlerLegacy: () => {}, 74 72 config: { 75 73 operationId: false, 76 74 response: 'body', 77 75 }, 76 + handler: () => {}, 77 + handlerLegacy: () => {}, 78 78 name: '@hey-api/sdk', 79 79 }, 80 80 }, ··· 85 85 pluginOrder: ['@hey-api/client-fetch', '@hey-api/sdk'], 86 86 plugins: { 87 87 '@hey-api/client-fetch': { 88 - _handler: () => {}, 89 - _handlerLegacy: () => {}, 90 - _tags: ['client'], 91 88 config: {}, 89 + handler: () => {}, 90 + handlerLegacy: () => {}, 92 91 name: '@hey-api/client-fetch', 92 + tags: ['client'], 93 93 }, 94 94 '@hey-api/sdk': { 95 - _handler: () => {}, 96 - _handlerLegacy: () => {}, 97 95 config: { 98 96 operationId: true, 99 97 response: 'body', 100 98 }, 99 + handler: () => {}, 100 + handlerLegacy: () => {}, 101 101 name: '@hey-api/sdk', 102 102 }, 103 103 }, ··· 108 108 pluginOrder: ['@hey-api/client-fetch', '@hey-api/sdk'], 109 109 plugins: { 110 110 '@hey-api/client-fetch': { 111 - _handler: () => {}, 112 - _handlerLegacy: () => {}, 113 - _tags: ['client'], 114 111 config: {}, 112 + handler: () => {}, 113 + handlerLegacy: () => {}, 115 114 name: '@hey-api/client-fetch', 115 + tags: ['client'], 116 116 }, 117 117 '@hey-api/sdk': { 118 - _handler: () => {}, 119 - _handlerLegacy: () => {}, 120 118 config: { 121 119 operationId: false, 122 120 response: 'body', 123 121 }, 122 + handler: () => {}, 123 + handlerLegacy: () => {}, 124 124 name: '@hey-api/sdk', 125 125 }, 126 126 },