Skip to content

Commit eb4fb3b

Browse files
authored
Merge pull request #2185 from hey-api/refactor/plugin-api
refactor: clean up more plugin types
2 parents d20e3a9 + 524f260 commit eb4fb3b

File tree

70 files changed

+649
-526
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+649
-526
lines changed

docs/openapi-ts/plugins/custom.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export interface Config {
5959
Reserved fields are prefixed with an underscore and are not exposed to the user.
6060
:::
6161

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.
6363

6464
::: code-group
6565

@@ -70,12 +70,12 @@ import { handler } from './plugin';
7070
import type { Config } from './types';
7171

7272
export const defaultConfig: Plugin.Config<Config> = {
73-
_dependencies: ['@hey-api/typescript'],
74-
_handler: handler,
75-
_handlerLegacy: () => {},
7673
config: {
7774
myOption: false, // implements default value from types
7875
},
76+
dependencies: ['@hey-api/typescript'],
77+
handler,
78+
handlerLegacy: () => {},
7979
name: 'my-plugin',
8080
output: 'my-plugin',
8181
};
@@ -101,7 +101,7 @@ Re-exporting your plugin from index file may result in broken output due to nami
101101

102102
## Handler
103103

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`.
105105

106106
::: code-group
107107

@@ -118,19 +118,19 @@ export const handler: Plugin.Handler<Config> = ({ context, plugin }) => {
118118
path: plugin.output,
119119
});
120120

121-
context.subscribe('before', () => {
121+
plugin.subscribe('before', () => {
122122
// do something before parsing the input
123123
});
124124

125-
context.subscribe('operation', ({ operation }) => {
125+
plugin.subscribe('operation', ({ operation }) => {
126126
// do something with the operation model
127127
});
128128

129-
context.subscribe('schema', ({ operation }) => {
129+
plugin.subscribe('schema', ({ operation }) => {
130130
// do something with the schema model
131131
});
132132

133-
context.subscribe('after', () => {
133+
plugin.subscribe('after', () => {
134134
// do something after parsing the input
135135
});
136136

@@ -159,7 +159,7 @@ export const handler: Plugin.Handler<Config> = ({ context, plugin }) => {
159159

160160
### Legacy
161161

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.
163163

164164
## Usage
165165

packages/custom-client/src/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ export interface Config extends Client.Config {
1616

1717
export const defaultConfig: Plugin.Config<Config> = {
1818
...clientDefaultMeta,
19-
_handler: clientPluginHandler,
20-
_handlerLegacy: () => {},
2119
config: {
2220
...clientDefaultConfig,
2321
bundle: false,
2422
},
23+
handler: clientPluginHandler,
24+
handlerLegacy: () => {},
2525
name: '@hey-api/custom-client',
2626
};
2727

packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/base-url-false/client/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export interface Config extends Client.Config {
1616

1717
export const defaultConfig: Plugin.Config<Config> = {
1818
...clientDefaultMeta,
19-
_handler: clientPluginHandler,
2019
config: clientDefaultConfig,
20+
handler: clientPluginHandler,
2121
name: __filename,
2222
};
2323

packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/base-url-number/client/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export interface Config extends Client.Config {
1616

1717
export const defaultConfig: Plugin.Config<Config> = {
1818
...clientDefaultMeta,
19-
_handler: clientPluginHandler,
2019
config: clientDefaultConfig,
20+
handler: clientPluginHandler,
2121
name: __filename,
2222
};
2323

packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/base-url-strict/client/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export interface Config extends Client.Config {
1616

1717
export const defaultConfig: Plugin.Config<Config> = {
1818
...clientDefaultMeta,
19-
_handler: clientPluginHandler,
2019
config: clientDefaultConfig,
20+
handler: clientPluginHandler,
2121
name: __filename,
2222
};
2323

packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/base-url-string/client/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export interface Config extends Client.Config {
1616

1717
export const defaultConfig: Plugin.Config<Config> = {
1818
...clientDefaultMeta,
19-
_handler: clientPluginHandler,
2019
config: clientDefaultConfig,
20+
handler: clientPluginHandler,
2121
name: __filename,
2222
};
2323

packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/bundle/client/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export interface Config extends Client.Config {
1616

1717
export const defaultConfig: Plugin.Config<Config> = {
1818
...clientDefaultMeta,
19-
_handler: clientPluginHandler,
2019
config: clientDefaultConfig,
20+
handler: clientPluginHandler,
2121
name: __filename,
2222
};
2323

packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/default/client/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export interface Config extends Client.Config {
1616

1717
export const defaultConfig: Plugin.Config<Config> = {
1818
...clientDefaultMeta,
19-
_handler: clientPluginHandler,
2019
config: clientDefaultConfig,
20+
handler: clientPluginHandler,
2121
name: __filename,
2222
};
2323

packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/sdk-client-optional/client/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export interface Config extends Client.Config {
1616

1717
export const defaultConfig: Plugin.Config<Config> = {
1818
...clientDefaultMeta,
19-
_handler: clientPluginHandler,
2019
config: clientDefaultConfig,
20+
handler: clientPluginHandler,
2121
name: __filename,
2222
};
2323

packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/sdk-client-required/client/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export interface Config extends Client.Config {
1616

1717
export const defaultConfig: Plugin.Config<Config> = {
1818
...clientDefaultMeta,
19-
_handler: clientPluginHandler,
2019
config: clientDefaultConfig,
20+
handler: clientPluginHandler,
2121
name: __filename,
2222
};
2323

0 commit comments

Comments
 (0)