swaggie 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -187,7 +187,7 @@ function buildNg2CreateClientMocks(
187
187
 
188
188
  function buildFrameworkImport(fw) {
189
189
  return fw === 'vitest'
190
- ? "import { vi } from 'vitest';\n"
190
+ ? "import { type MockInstance, vi } from 'vitest';\n"
191
191
  : "import { jest } from '@jest/globals';\n";
192
192
  }
193
193
 
@@ -302,14 +302,22 @@ const defaultMutationReturn = {
302
302
  }
303
303
 
304
304
  function buildTsqHelpers(fw) {
305
- const ref = fwRef(fw);
306
305
  return `\
307
306
  // ─── TanStack Query mock helpers ─────────────────────────────────────────────
308
307
 
308
+ interface MockQueryReturn {
309
+ /** The data to return from the mock */
310
+ data: unknown;
311
+ /** Whether to return a loading state (default: false) */
312
+ isLoading?: boolean;
313
+ /** Whether to return an error (default: undefined) */
314
+ error?: Error | null;
315
+ }
316
+
309
317
  /** Augments a spy with a \`mockQuery\` shorthand for useQuery hooks. */
310
- function withMockQuery<T extends ReturnType<typeof ${ref}.spyOn>>(spy: T) {
318
+ function withMockQuery<T extends MockInstance>(spy: T) {
311
319
  return Object.assign(spy, {
312
- mockQuery({ data, isLoading, error }: { data?: unknown; isLoading?: boolean; error?: Error }) {
320
+ mockQuery({ data, isLoading, error }: MockQueryReturn) {
313
321
  const pending = isLoading ?? false;
314
322
  spy.mockReturnValue({
315
323
  ...defaultQueryReturn,
@@ -324,10 +332,19 @@ function withMockQuery<T extends ReturnType<typeof ${ref}.spyOn>>(spy: T) {
324
332
  });
325
333
  }
326
334
 
335
+ interface MockMutationReturn {
336
+ /** The data to return from the mock */
337
+ data: unknown;
338
+ /** Whether to return a mutating state (default: false) */
339
+ isPending?: boolean;
340
+ /** Whether to return an error (default: undefined) */
341
+ error?: Error | null;
342
+ }
343
+
327
344
  /** Augments a spy with a \`mockMutation\` shorthand for useMutation hooks. */
328
- function withMockMutation<T extends ReturnType<typeof ${ref}.spyOn>>(spy: T) {
345
+ function withMockMutation<T extends MockInstance>(spy: T) {
329
346
  return Object.assign(spy, {
330
- mockMutation({ data, isPending, error }: { data?: unknown; isPending?: boolean; error?: Error }) {
347
+ mockMutation({ data, isPending, error }: MockMutationReturn) {
331
348
  spy.mockReturnValue({
332
349
  ...defaultMutationReturn,
333
350
  mutate: ${fn(fw)},
@@ -416,7 +433,7 @@ function buildCreateTsqHookMocks(
416
433
  for (const op of getOps) {
417
434
  const hookName = toHookName(op.name, 'use');
418
435
  lines.push(
419
- ` ${hookName}: withMockQuery(${spy}(realApi.${camelName}.queries, '${hookName}').mockReturnValue(defaultQueryReturn)),`
436
+ ` ${hookName}: withMockQuery(${spy}(realApi.${camelName}.queries, '${hookName}').mockReturnValue(defaultQueryReturn as any)),`
420
437
  );
421
438
  }
422
439
  lines.push(' },');
@@ -424,7 +441,7 @@ function buildCreateTsqHookMocks(
424
441
  for (const op of mutOps) {
425
442
  const hookName = 'use' + _case.pascal.call(void 0, op.name);
426
443
  lines.push(
427
- ` ${hookName}: withMockMutation(${spy}(realApi.${camelName}.mutations, '${hookName}').mockReturnValue(defaultMutationReturn)),`
444
+ ` ${hookName}: withMockMutation(${spy}(realApi.${camelName}.mutations, '${hookName}').mockReturnValue(defaultMutationReturn as any)),`
428
445
  );
429
446
  }
430
447
  lines.push(' },');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swaggie",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Generate a fully typed TypeScript API client from your OpenAPI 3 spec",
5
5
  "author": {
6
6
  "name": "Piotr Dabrowski",