Skip to content

Commit 403b442

Browse files
committed
chore: clean up types
1 parent 4679c6d commit 403b442

File tree

7 files changed

+239
-247
lines changed

7 files changed

+239
-247
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
"@hey-api/openapi-ts": patch
3+
"@hey-api/shared": patch
34
---
45

5-
Warn when the same plugin is specified multiple times in the plugins array
6+
**config**: warn on duplicated plugin configurations

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { AnyPluginName, PluginContext, PluginNames } from '@hey-api/shared'
22
import {
33
dependencyFactory,
44
valueToObject,
5-
warnDuplicatePlugins,
5+
warnOnConflictingDuplicatePlugins,
66
} from '@hey-api/shared';
77

88
import { defaultPluginConfigs } from '../plugins/config';
@@ -147,7 +147,7 @@ export function getPlugins({
147147
}
148148
}
149149

150-
warnDuplicatePlugins(definedPlugins as ReadonlyArray<never>);
150+
warnOnConflictingDuplicatePlugins(definedPlugins);
151151

152152
const userPlugins = definedPlugins
153153
.map((plugin) => {

packages/openapi-ts/src/__tests__/index.test.ts

Lines changed: 0 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -286,218 +286,6 @@ describe('createClient', () => {
286286
expect(results).toHaveLength(4);
287287
});
288288

289-
describe('duplicate plugin warnings', () => {
290-
const baseConfig = {
291-
dryRun: true as const,
292-
input: {
293-
info: { title: 'duplicate-plugin-test', version: '1.0.0' },
294-
openapi: '3.1.0' as const,
295-
},
296-
logs: {
297-
level: 'silent' as const,
298-
},
299-
output: 'output',
300-
};
301-
302-
const conflictWarnings = (warnSpy: ReturnType<typeof vi.spyOn>) =>
303-
warnSpy.mock.calls.filter(
304-
(args: unknown[]) => typeof args[0] === 'string' && args[0].includes('conflicting options'),
305-
);
306-
307-
it('warns when the same plugin is specified with conflicting options', async () => {
308-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
309-
310-
await createClient({
311-
...baseConfig,
312-
plugins: [
313-
{ case: 'PascalCase', name: '@hey-api/typescript' },
314-
{ case: 'camelCase', name: '@hey-api/typescript' },
315-
],
316-
});
317-
318-
expect(conflictWarnings(warnSpy)).toHaveLength(1);
319-
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('"@hey-api/typescript"'));
320-
321-
warnSpy.mockRestore();
322-
});
323-
324-
it('does not warn when the same plugin is specified twice as a string', async () => {
325-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
326-
327-
await createClient({
328-
...baseConfig,
329-
plugins: ['@hey-api/typescript', '@hey-api/typescript'],
330-
});
331-
332-
expect(conflictWarnings(warnSpy)).toHaveLength(0);
333-
334-
warnSpy.mockRestore();
335-
});
336-
337-
it('does not warn when a string and an object with only name are specified', async () => {
338-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
339-
340-
await createClient({
341-
...baseConfig,
342-
plugins: ['@hey-api/typescript', { name: '@hey-api/typescript' }],
343-
});
344-
345-
expect(conflictWarnings(warnSpy)).toHaveLength(0);
346-
347-
warnSpy.mockRestore();
348-
});
349-
350-
it('does not warn when two identical object configurations are specified', async () => {
351-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
352-
353-
await createClient({
354-
...baseConfig,
355-
plugins: [
356-
{ case: 'PascalCase', name: '@hey-api/typescript' },
357-
{ case: 'PascalCase', name: '@hey-api/typescript' },
358-
],
359-
});
360-
361-
expect(conflictWarnings(warnSpy)).toHaveLength(0);
362-
363-
warnSpy.mockRestore();
364-
});
365-
366-
it('does not warn when objects differ only in key order', async () => {
367-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
368-
369-
await createClient({
370-
...baseConfig,
371-
plugins: [
372-
{ case: 'PascalCase', name: '@hey-api/typescript' },
373-
{ name: '@hey-api/typescript', case: 'PascalCase' },
374-
],
375-
});
376-
377-
expect(conflictWarnings(warnSpy)).toHaveLength(0);
378-
379-
warnSpy.mockRestore();
380-
});
381-
382-
it('does not warn when nested object configs differ only in key order', async () => {
383-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
384-
385-
await createClient({
386-
...baseConfig,
387-
plugins: [
388-
{
389-
definitions: { case: 'PascalCase', name: 'foo' },
390-
name: '@hey-api/typescript',
391-
},
392-
{
393-
name: '@hey-api/typescript',
394-
definitions: { name: 'foo', case: 'PascalCase' },
395-
},
396-
],
397-
});
398-
399-
expect(conflictWarnings(warnSpy)).toHaveLength(0);
400-
401-
warnSpy.mockRestore();
402-
});
403-
404-
it('warns when an object adds extra config compared to a string entry', async () => {
405-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
406-
407-
await createClient({
408-
...baseConfig,
409-
plugins: ['@hey-api/typescript', { case: 'PascalCase', name: '@hey-api/typescript' }],
410-
});
411-
412-
expect(conflictWarnings(warnSpy)).toHaveLength(1);
413-
414-
warnSpy.mockRestore();
415-
});
416-
417-
it('does not warn when array-valued options differ only in element key order', async () => {
418-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
419-
420-
await createClient({
421-
...baseConfig,
422-
plugins: [
423-
{
424-
items: [{ from: 'foo', name: 'bar' }],
425-
name: '@hey-api/typescript',
426-
} as never,
427-
{
428-
items: [{ name: 'bar', from: 'foo' }],
429-
name: '@hey-api/typescript',
430-
} as never,
431-
],
432-
});
433-
434-
expect(conflictWarnings(warnSpy)).toHaveLength(0);
435-
436-
warnSpy.mockRestore();
437-
});
438-
439-
it('warns when array-valued options differ in element order', async () => {
440-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
441-
442-
await createClient({
443-
...baseConfig,
444-
plugins: [
445-
{
446-
items: [{ from: 'a', name: 'x' }, { from: 'b', name: 'y' }],
447-
name: '@hey-api/typescript',
448-
} as never,
449-
{
450-
items: [{ from: 'b', name: 'y' }, { from: 'a', name: 'x' }],
451-
name: '@hey-api/typescript',
452-
} as never,
453-
],
454-
});
455-
456-
expect(conflictWarnings(warnSpy)).toHaveLength(1);
457-
458-
warnSpy.mockRestore();
459-
});
460-
461-
it('does not warn when function-valued options have identical source', async () => {
462-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
463-
const transform = (s: string) => s.toUpperCase();
464-
465-
await createClient({
466-
...baseConfig,
467-
plugins: [
468-
{ definitions: { name: transform }, name: '@hey-api/typescript' },
469-
{ definitions: { name: transform }, name: '@hey-api/typescript' },
470-
],
471-
});
472-
473-
expect(conflictWarnings(warnSpy)).toHaveLength(0);
474-
475-
warnSpy.mockRestore();
476-
});
477-
478-
it('warns when function-valued options differ', async () => {
479-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
480-
481-
await createClient({
482-
...baseConfig,
483-
plugins: [
484-
{
485-
definitions: { name: (s: string) => s.toUpperCase() },
486-
name: '@hey-api/typescript',
487-
},
488-
{
489-
definitions: { name: (s: string) => s.toLowerCase() },
490-
name: '@hey-api/typescript',
491-
},
492-
],
493-
});
494-
495-
expect(conflictWarnings(warnSpy)).toHaveLength(1);
496-
497-
warnSpy.mockRestore();
498-
});
499-
});
500-
501289
it('executes @angular/common HttpRequest builder path', async () => {
502290
const results = await createClient({
503291
dryRun: true,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { AnyPluginName, PluginContext, PluginNames } from '@hey-api/shared'
22
import {
33
dependencyFactory,
44
valueToObject,
5-
warnDuplicatePlugins,
5+
warnOnConflictingDuplicatePlugins,
66
} from '@hey-api/shared';
77

88
import { defaultPluginConfigs } from '../plugins/config';
@@ -150,7 +150,7 @@ export function getPlugins({
150150
}
151151
}
152152

153-
warnDuplicatePlugins(definedPlugins as ReadonlyArray<never>);
153+
warnOnConflictingDuplicatePlugins(definedPlugins);
154154

155155
const userPlugins = definedPlugins
156156
.map((plugin) => {

packages/shared/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export type {
9999
OpenApiSchemaObject,
100100
} from './openApi/types';
101101
export type { GetNameContext, Hooks } from './parser/hooks';
102-
export { warnDuplicatePlugins } from './plugins/duplicate';
102+
export { warnOnConflictingDuplicatePlugins } from './plugins/duplicate';
103103
export type { SchemaWithType } from './plugins/shared/types/schema';
104104
export { definePluginConfig, mappers } from './plugins/shared/utils/config';
105105
export type { PluginInstanceTypes } from './plugins/shared/utils/instance';

0 commit comments

Comments
 (0)