Skip to content

Commit 05070b3

Browse files
committed
chore: clean up
1 parent 947cfa8 commit 05070b3

File tree

14 files changed

+87
-24
lines changed

14 files changed

+87
-24
lines changed

.changeset/five-pianos-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/openapi-ts": patch
3+
---
4+
5+
**plugin(@hey-api/examples)**: initial release

packages/openapi-python/src/plugins/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export type PluginClientNames =
44
| '@hey-api/client-requests'
55
| '@hey-api/client-urllib3';
66

7-
export type PluginMockNames = 'factory_boy' | 'faker' | 'mimesis';
7+
export type PluginSourceNames = 'factory_boy' | 'faker' | 'mimesis';
88

99
export type PluginTransformerNames = never;
1010

packages/openapi-ts/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ declare module '@hey-api/shared' {
6868
'@hey-api/client-next': Plugins.HeyApiClientNext.Types['Types'];
6969
'@hey-api/client-nuxt': Plugins.HeyApiClientNuxt.Types['Types'];
7070
'@hey-api/client-ofetch': Plugins.HeyApiClientOfetch.Types['Types'];
71+
'@hey-api/examples': Plugins.HeyApiExamples.Types['Types'];
7172
'@hey-api/schemas': Plugins.HeyApiSchemas.Types['Types'];
7273
'@hey-api/sdk': Plugins.HeyApiSdk.Types['Types'];
7374
'@hey-api/transformers': Plugins.HeyApiTransformers.Types['Types'];
@@ -128,6 +129,7 @@ import type {
128129
HeyApiClientOfetchPlugin,
129130
OfetchClient as OfetchClientImp,
130131
} from './plugins/@hey-api/client-ofetch';
132+
import type { HeyApiExamplesPlugin } from './plugins/@hey-api/examples';
131133
import type { HeyApiSchemasPlugin } from './plugins/@hey-api/schemas';
132134
import type { HeyApiSdkPlugin } from './plugins/@hey-api/sdk';
133135
import type { HeyApiTransformersPlugin } from './plugins/@hey-api/transformers';
@@ -250,6 +252,10 @@ export namespace Plugins {
250252
export type Types = HeyApiClientOfetchPlugin;
251253
}
252254

255+
export namespace HeyApiExamples {
256+
export type Types = HeyApiExamplesPlugin;
257+
}
258+
253259
export namespace HeyApiSchemas {
254260
export type Types = HeyApiSchemasPlugin;
255261
}

packages/openapi-ts/src/plugins/@faker-js/faker/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const defaultConfig: FakerJsFakerPlugin['Config'] = {
2424
value: plugin.config.definitions,
2525
});
2626
},
27-
tags: ['mocker'],
27+
tags: ['source'],
2828
};
2929

3030
/**
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { definePluginConfig } from '@hey-api/shared';
2+
3+
// import { handler } from './plugin';
4+
import type { HeyApiExamplesPlugin } from './types';
5+
6+
export const defaultConfig: HeyApiExamplesPlugin['Config'] = {
7+
config: {
8+
case: 'camelCase',
9+
includeInEntry: false,
10+
},
11+
// handler,
12+
handler: () => {},
13+
name: '@hey-api/examples',
14+
tags: ['source'],
15+
};
16+
17+
/**
18+
* Type helper for `@hey-api/examples` plugin, returns {@link Plugin.Config} object
19+
*/
20+
export const defineConfig = definePluginConfig(defaultConfig);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { defaultConfig, defineConfig } from './config';
2+
export type { HeyApiExamplesPlugin } from './types';
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { Casing } from '@hey-api/shared';
2+
import type { DefinePlugin, Plugin } from '@hey-api/shared';
3+
4+
export type UserConfig = Plugin.Name<'@hey-api/examples'> &
5+
// Plugin.Hooks &
6+
Plugin.UserExports & {
7+
// Resolvers & {
8+
/**
9+
* Casing convention for generated names.
10+
*
11+
* @default 'camelCase'
12+
*/
13+
case?: Casing;
14+
};
15+
16+
export type Config = Plugin.Name<'@hey-api/examples'> &
17+
// Plugin.Hooks &
18+
Plugin.Exports & {
19+
// Resolvers & {
20+
/** Casing convention for generated names. */
21+
case: Casing;
22+
};
23+
24+
export type HeyApiExamplesPlugin = DefinePlugin<UserConfig, Config>;

packages/openapi-ts/src/plugins/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { defaultConfig as heyApiClientKy } from '../plugins/@hey-api/client-ky';
99
import { defaultConfig as heyApiClientNext } from '../plugins/@hey-api/client-next';
1010
import { defaultConfig as heyApiClientNuxt } from '../plugins/@hey-api/client-nuxt';
1111
import { defaultConfig as heyApiClientOfetch } from '../plugins/@hey-api/client-ofetch';
12+
import { defaultConfig as heyApiExamples } from '../plugins/@hey-api/examples';
1213
import { defaultConfig as heyApiSchemas } from '../plugins/@hey-api/schemas';
1314
import { defaultConfig as heyApiSdk } from '../plugins/@hey-api/sdk';
1415
import { defaultConfig as heyApiTransformers } from '../plugins/@hey-api/transformers';
@@ -41,6 +42,7 @@ export const defaultPluginConfigs: {
4142
'@hey-api/client-next': heyApiClientNext,
4243
'@hey-api/client-nuxt': heyApiClientNuxt,
4344
'@hey-api/client-ofetch': heyApiClientOfetch,
45+
'@hey-api/examples': heyApiExamples,
4446
'@hey-api/schemas': heyApiSchemas,
4547
'@hey-api/sdk': heyApiSdk,
4648
'@hey-api/transformers': heyApiTransformers,

packages/openapi-ts/src/plugins/msw/config.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,23 @@ export const defaultConfig: MswPlugin['Config'] = {
99
comments: true,
1010
includeInEntry: false,
1111
responseFallback: 'error',
12-
valueSources: ['example'],
12+
source: ['@hey-api/examples'],
1313
},
1414
dependencies: ['@hey-api/typescript'],
1515
handler,
1616
name: 'msw',
17-
tags: ['mocker'],
17+
resolveConfig: (plugin) => {
18+
if (!(plugin.config.source instanceof Array)) {
19+
plugin.config.source = plugin.config.source ? [plugin.config.source] : [];
20+
}
21+
for (const source of plugin.config.source) {
22+
plugin.dependencies.add(source);
23+
}
24+
},
25+
tags: ['handler'],
1826
};
1927

2028
/**
21-
* Type helper for `msw` plugin, returns {@link Plugin.Config} object
29+
* Type helper for MSW plugin, returns {@link Plugin.Config} object
2230
*/
2331
export const defineConfig = definePluginConfig(defaultConfig);

packages/openapi-ts/src/plugins/msw/shared/handler.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,10 @@ function createHandlerNode({
153153

154154
export function getHandler({
155155
baseUrl,
156-
examples,
157156
operation,
158157
plugin,
159158
}: {
160159
baseUrl: string | undefined;
161-
examples: boolean;
162160
operation: IR.OperationObject;
163161
plugin: MswPlugin['Instance'];
164162
}): Symbol {
@@ -212,8 +210,8 @@ export function getHandler({
212210
// omit response type to avoid DefaultBodyType constraint issues
213211
);
214212

215-
// When examples are disabled, strip the example from the dominant response
216-
if (!examples) {
213+
if (!plugin.config.source.includes('@hey-api/examples')) {
214+
// examples are disabled, strip the example from the dominant response
217215
response.example = undefined;
218216
}
219217

0 commit comments

Comments
 (0)