swaggie 2.1.3 → 2.1.4

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.
@@ -67,8 +67,13 @@ const MOCK_FILE_HEADER = `\
67
67
  .map((name) => {
68
68
  const fullName = servicePrefix + name;
69
69
  const camelName = _case.camel.call(void 0, fullName);
70
+ // `default` is a JS reserved word and cannot be used as a standalone
71
+ // `export const` identifier. The hooks templates rename it to `main`
72
+ // (see genOperations.ts — hooksCamelCaseName). Mock code that references
73
+ // the hooks namespace must use the same safe name.
74
+ const hooksCamelName = camelName === 'default' ? 'main' : camelName;
70
75
  const ops = _genOperations.prepareOperations.call(void 0, groups[name], options, spec.components);
71
- return { name, camelName, ops };
76
+ return { name, camelName, hooksCamelName, ops };
72
77
  })
73
78
  .filter((g) => g.ops.length > 0);
74
79
 
@@ -399,16 +404,16 @@ function buildCreateSwrHookMocks(
399
404
  const spy = spyFn(fw);
400
405
  const lines = ['export function createApiHookMocks() {', ' return {'];
401
406
 
402
- for (const { camelName, ops } of groups) {
407
+ for (const { hooksCamelName, ops } of groups) {
403
408
  const getOps = ops.filter((o) => o.method === 'GET');
404
409
  const mutOps = ops.filter((o) => o.method !== 'GET');
405
410
 
406
- lines.push(` ${camelName}: {`);
411
+ lines.push(` ${hooksCamelName}: {`);
407
412
  lines.push(' queries: {');
408
413
  for (const op of getOps) {
409
414
  const hookName = toHookName(op.name, 'use');
410
415
  lines.push(
411
- ` ${hookName}: withMockSWR(${spy}(${hooksAlias}.${camelName}.queries, '${hookName}').mockReturnValue(defaultSWRReturn)),`
416
+ ` ${hookName}: withMockSWR(${spy}(${hooksAlias}.${hooksCamelName}.queries, '${hookName}').mockReturnValue(defaultSWRReturn)),`
412
417
  );
413
418
  }
414
419
  lines.push(' },');
@@ -416,7 +421,7 @@ function buildCreateSwrHookMocks(
416
421
  for (const op of mutOps) {
417
422
  const hookName = 'use' + _case.pascal.call(void 0, op.name);
418
423
  lines.push(
419
- ` ${hookName}: withMockSWRMutation(${spy}(${hooksAlias}.${camelName}.mutations, '${hookName}').mockReturnValue(defaultSWRMutationReturn as any)),`
424
+ ` ${hookName}: withMockSWRMutation(${spy}(${hooksAlias}.${hooksCamelName}.mutations, '${hookName}').mockReturnValue(defaultSWRMutationReturn as any)),`
420
425
  );
421
426
  }
422
427
  lines.push(' },');
@@ -436,16 +441,16 @@ function buildCreateTsqHookMocks(
436
441
  const spy = spyFn(fw);
437
442
  const lines = ['export function createApiHookMocks() {', ' return {'];
438
443
 
439
- for (const { camelName, ops } of groups) {
444
+ for (const { hooksCamelName, ops } of groups) {
440
445
  const getOps = ops.filter((o) => o.method === 'GET');
441
446
  const mutOps = ops.filter((o) => o.method !== 'GET');
442
447
 
443
- lines.push(` ${camelName}: {`);
448
+ lines.push(` ${hooksCamelName}: {`);
444
449
  lines.push(' queries: {');
445
450
  for (const op of getOps) {
446
451
  const hookName = toHookName(op.name, 'use');
447
452
  lines.push(
448
- ` ${hookName}: withMockQuery(${spy}(${hooksAlias}.${camelName}.queries, '${hookName}').mockReturnValue(defaultQueryReturn as any)),`
453
+ ` ${hookName}: withMockQuery(${spy}(${hooksAlias}.${hooksCamelName}.queries, '${hookName}').mockReturnValue(defaultQueryReturn as any)),`
449
454
  );
450
455
  }
451
456
  lines.push(' },');
@@ -453,7 +458,7 @@ function buildCreateTsqHookMocks(
453
458
  for (const op of mutOps) {
454
459
  const hookName = 'use' + _case.pascal.call(void 0, op.name);
455
460
  lines.push(
456
- ` ${hookName}: withMockMutation(${spy}(${hooksAlias}.${camelName}.mutations, '${hookName}').mockReturnValue(defaultMutationReturn as any)),`
461
+ ` ${hookName}: withMockMutation(${spy}(${hooksAlias}.${hooksCamelName}.mutations, '${hookName}').mockReturnValue(defaultMutationReturn as any)),`
457
462
  );
458
463
  }
459
464
  lines.push(' },');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swaggie",
3
- "version": "2.1.3",
3
+ "version": "2.1.4",
4
4
  "description": "Generate a fully typed TypeScript API client from your OpenAPI 3 spec",
5
5
  "author": {
6
6
  "name": "Piotr Dabrowski",
@@ -73,11 +73,11 @@
73
73
  "case": "^1.6.3",
74
74
  "commander": "^14.0.3",
75
75
  "eta": "^4.6.0",
76
- "yaml": "^2.8.3",
76
+ "yaml": "^2.9.0",
77
77
  "picocolors": "^1.1.1"
78
78
  },
79
79
  "devDependencies": {
80
- "bun-types": "1.3.13",
80
+ "bun-types": "1.3.14",
81
81
  "openapi-types": "^12.1.3",
82
82
  "sucrase": "3.35.1",
83
83
  "typescript": "6.0.3",