@kubb/plugin-msw 4.1.4 → 4.2.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.
Files changed (44) hide show
  1. package/dist/{components-Bcz4mvn3.cjs → components-CULOceYX.cjs} +34 -1
  2. package/dist/components-CULOceYX.cjs.map +1 -0
  3. package/dist/{components-Ba13vW1_.js → components-DcRndqwD.js} +29 -2
  4. package/dist/components-DcRndqwD.js.map +1 -0
  5. package/dist/components.cjs +3 -2
  6. package/dist/components.d.cts +21 -8
  7. package/dist/components.d.ts +21 -8
  8. package/dist/components.js +2 -2
  9. package/dist/{generators-DgwpklSC.cjs → generators-BpCsxN0-.cjs} +31 -7
  10. package/dist/generators-BpCsxN0-.cjs.map +1 -0
  11. package/dist/{generators-lMP39igU.js → generators-itHERcU2.js} +31 -8
  12. package/dist/generators-itHERcU2.js.map +1 -0
  13. package/dist/generators.cjs +2 -2
  14. package/dist/generators.d.cts +2 -2
  15. package/dist/generators.d.ts +2 -2
  16. package/dist/generators.js +2 -2
  17. package/dist/index.cjs +7 -7
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +2 -2
  20. package/dist/index.d.ts +2 -2
  21. package/dist/index.js +7 -7
  22. package/dist/index.js.map +1 -1
  23. package/dist/{types-BOMj2hjt.d.ts → types-8ZXwr93_.d.cts} +2 -2
  24. package/dist/{types-BdC96j80.d.ts → types-BB6ZV1EN.d.cts} +79 -123
  25. package/dist/{types-DLxzBV0T.d.cts → types-BLiYk9M7.d.ts} +79 -123
  26. package/dist/{types-DYAniEBx.d.cts → types-IbHKcY02.d.ts} +2 -2
  27. package/package.json +8 -10
  28. package/src/components/Handlers.tsx +1 -2
  29. package/src/components/Mock.tsx +1 -2
  30. package/src/components/MockWithFaker.tsx +1 -2
  31. package/src/components/Response.tsx +42 -0
  32. package/src/components/index.ts +1 -0
  33. package/src/generators/__snapshots__/createPet.ts +6 -0
  34. package/src/generators/__snapshots__/createPetFaker.ts +6 -0
  35. package/src/generators/__snapshots__/getPets.ts +15 -0
  36. package/src/generators/__snapshots__/getPetsFaker.ts +15 -0
  37. package/src/generators/__snapshots__/showPetById.ts +9 -0
  38. package/src/generators/handlersGenerator.tsx +5 -2
  39. package/src/generators/mswGenerator.tsx +37 -8
  40. package/src/plugin.ts +6 -9
  41. package/dist/components-Ba13vW1_.js.map +0 -1
  42. package/dist/components-Bcz4mvn3.cjs.map +0 -1
  43. package/dist/generators-DgwpklSC.cjs.map +0 -1
  44. package/dist/generators-lMP39igU.js.map +0 -1
@@ -1,10 +1,11 @@
1
- import { HttpMethod, OasTypes, Operation as Operation$1, SchemaObject as SchemaObject$1, contentType } from "./types-DYAniEBx.cjs";
1
+ import { a as contentType, i as SchemaObject$1, n as OasTypes, r as Operation$1, t as HttpMethod } from "./types-IbHKcY02.js";
2
2
  import { OASDocument, SchemaObject, User } from "oas/types";
3
3
  import { Operation } from "oas/operation";
4
4
  import { OpenAPIV3 } from "openapi-types";
5
5
  import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
6
6
  import BaseOas from "oas";
7
7
  import { ConsolaInstance, LogLevel } from "consola";
8
+ import { FileManager } from "@kubb/fabric-core";
8
9
 
9
10
  //#region ../oas/src/Oas.d.ts
10
11
  type Options$3 = {
@@ -39,17 +40,17 @@ declare class Oas<const TOAS = unknown> extends BaseOas {
39
40
  * Abstract class that contains the building blocks for plugins to create their own Generator
40
41
  * @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
41
42
  */
42
- declare abstract class BaseGenerator<TOptions = unknown, TContext = unknown> {
43
+ declare abstract class BaseGenerator<TOptions$1 = unknown, TContext = unknown> {
43
44
  #private;
44
- constructor(options?: TOptions, context?: TContext);
45
- get options(): TOptions;
45
+ constructor(options?: TOptions$1, context?: TContext);
46
+ get options(): TOptions$1;
46
47
  get context(): TContext;
47
- set options(options: TOptions);
48
+ set options(options: TOptions$1);
48
49
  abstract build(...params: unknown[]): unknown;
49
50
  }
50
51
  //#endregion
51
52
  //#region ../core/src/fs/types.d.ts
52
- type BasePath<T extends string = string> = `${T}/`;
53
+ type BasePath<T$1 extends string = string> = `${T$1}/`;
53
54
  type Import = {
54
55
  /**
55
56
  * Import name to be used
@@ -123,7 +124,7 @@ type BaseName = `${string}.${string}`;
123
124
  * Path will be full qualified path to a specified file
124
125
  */
125
126
  type Path = string;
126
- type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
127
+ type AdvancedPath<T$1 extends BaseName = BaseName> = `${BasePath}${T$1}`;
127
128
  type OptionalPath = Path | undefined | null;
128
129
  type File<TMeta extends object = object> = {
129
130
  /**
@@ -212,9 +213,7 @@ type Logger = {
212
213
  };
213
214
  //#endregion
214
215
  //#region ../core/src/utils/types.d.ts
215
- type PossiblePromise<T> = Promise<T> | T;
216
- type ArrayWithLength<T extends number, U extends any[] = []> = U['length'] extends T ? U : ArrayWithLength<T, [true, ...U]>;
217
- type GreaterThan<T extends number, U extends number> = ArrayWithLength<U> extends [...ArrayWithLength<T>, ...infer _] ? false : true;
216
+ type PossiblePromise<T$1> = Promise<T$1> | T$1;
218
217
  //#endregion
219
218
  //#region ../core/src/types.d.ts
220
219
  type InputPath = {
@@ -327,11 +326,11 @@ TName extends string = string,
327
326
  /**
328
327
  * Options of the plugin.
329
328
  */
330
- TOptions extends object = object,
329
+ TOptions$1 extends object = object,
331
330
  /**
332
331
  * Options of the plugin that can be used later on, see `options` inside your plugin config.
333
332
  */
334
- TResolvedOptions extends object = TOptions,
333
+ TResolvedOptions extends object = TOptions$1,
335
334
  /**
336
335
  * Context that you want to expose to other plugins.
337
336
  */
@@ -345,23 +344,23 @@ TResolvePathOptions extends object = object> = {
345
344
  * Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
346
345
  */
347
346
  key: PluginKey<TName | string>;
348
- options: TOptions;
347
+ options: TOptions$1;
349
348
  resolvedOptions: TResolvedOptions;
350
349
  context: TContext;
351
350
  resolvePathOptions: TResolvePathOptions;
352
351
  };
353
352
  type PluginKey<TName> = [name: TName, identifier?: string | number];
354
- type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
353
+ type UserPlugin<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
355
354
  /**
356
355
  * Unique name used for the plugin
357
356
  * The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
358
357
  * @example @kubb/typescript
359
358
  */
360
- name: TOptions['name'];
359
+ name: TOptions$1['name'];
361
360
  /**
362
361
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
363
362
  */
364
- options: TOptions['resolvedOptions'];
363
+ options: TOptions$1['resolvedOptions'];
365
364
  /**
366
365
  * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
367
366
  * Can be used to validate dependent plugins.
@@ -371,23 +370,23 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
371
370
  * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
372
371
  */
373
372
  post?: Array<string>;
374
- } & (TOptions['context'] extends never ? {
373
+ } & (TOptions$1['context'] extends never ? {
375
374
  context?: never;
376
375
  } : {
377
- context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
376
+ context: (this: TOptions$1['name'] extends 'core' ? null : Omit<PluginContext<TOptions$1>, 'addFile'>) => TOptions$1['context'];
378
377
  });
379
- type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
380
- type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
378
+ type UserPluginWithLifeCycle<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions$1> & PluginLifecycle<TOptions$1>;
379
+ type Plugin<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
381
380
  /**
382
381
  * Unique name used for the plugin
383
382
  * @example @kubb/typescript
384
383
  */
385
- name: TOptions['name'];
384
+ name: TOptions$1['name'];
386
385
  /**
387
386
  * Internal key used when a developer uses more than one of the same plugin
388
387
  * @private
389
388
  */
390
- key: TOptions['key'];
389
+ key: TOptions$1['key'];
391
390
  /**
392
391
  * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
393
392
  * Can be used to validate dependent plugins.
@@ -400,49 +399,49 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
400
399
  /**
401
400
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
402
401
  */
403
- options: TOptions['resolvedOptions'];
404
- } & (TOptions['context'] extends never ? {
402
+ options: TOptions$1['resolvedOptions'];
403
+ } & (TOptions$1['context'] extends never ? {
405
404
  context?: never;
406
405
  } : {
407
- context: TOptions['context'];
406
+ context: TOptions$1['context'];
408
407
  });
409
- type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
410
- type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
408
+ type PluginWithLifeCycle<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions$1> & PluginLifecycle<TOptions$1>;
409
+ type PluginLifecycle<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
411
410
  /**
412
411
  * Start of the lifecycle of a plugin.
413
412
  * @type hookParallel
414
413
  */
415
- buildStart?: (this: PluginContext<TOptions>, Config: Config) => PossiblePromise<void>;
414
+ buildStart?: (this: PluginContext<TOptions$1>, Config: Config) => PossiblePromise<void>;
416
415
  /**
417
416
  * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
418
417
  * Options can als be included.
419
418
  * @type hookFirst
420
419
  * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
421
420
  */
422
- resolvePath?: (this: PluginContext<TOptions>, baseName: BaseName, mode?: Mode, options?: TOptions['resolvePathOptions']) => OptionalPath;
421
+ resolvePath?: (this: PluginContext<TOptions$1>, baseName: BaseName, mode?: Mode, options?: TOptions$1['resolvePathOptions']) => OptionalPath;
423
422
  /**
424
423
  * Resolve to a name based on a string.
425
424
  * Useful when converting to PascalCase or camelCase.
426
425
  * @type hookFirst
427
426
  * @example ('pet') => 'Pet'
428
427
  */
429
- resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
428
+ resolveName?: (this: PluginContext<TOptions$1>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
430
429
  /**
431
430
  * End of the plugin lifecycle.
432
431
  * @type hookParallel
433
432
  */
434
- buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
433
+ buildEnd?: (this: PluginContext<TOptions$1>) => PossiblePromise<void>;
435
434
  };
436
435
  type PluginLifecycleHooks = keyof PluginLifecycle;
437
- type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
438
- type ResolvePathParams<TOptions = object> = {
436
+ type PluginParameter<H$1 extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H$1]>;
437
+ type ResolvePathParams<TOptions$1 = object> = {
439
438
  pluginKey?: Plugin['key'];
440
439
  baseName: BaseName;
441
440
  mode?: Mode;
442
441
  /**
443
442
  * Options to be passed to 'resolvePath' 3th parameter
444
443
  */
445
- options?: TOptions;
444
+ options?: TOptions$1;
446
445
  };
447
446
  type ResolveNameParams = {
448
447
  name: string;
@@ -455,12 +454,15 @@ type ResolveNameParams = {
455
454
  */
456
455
  type?: 'file' | 'function' | 'type' | 'const';
457
456
  };
458
- type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
457
+ type PluginContext<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
459
458
  config: Config;
459
+ /**
460
+ * @deprecated
461
+ */
460
462
  fileManager: FileManager;
461
463
  pluginManager: PluginManager;
462
464
  addFile: (...file: Array<File>) => Promise<Array<ResolvedFile>>;
463
- resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => OptionalPath;
465
+ resolvePath: (params: ResolvePathParams<TOptions$1['resolvePathOptions']>) => OptionalPath;
464
466
  resolveName: (params: ResolveNameParams) => string;
465
467
  logger: Logger;
466
468
  /**
@@ -470,12 +472,12 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
470
472
  /**
471
473
  * Current plugin
472
474
  */
473
- plugin: Plugin<TOptions>;
475
+ plugin: Plugin<TOptions$1>;
474
476
  };
475
477
  /**
476
478
  * Specify the export location for the files and define the behavior of the output
477
479
  */
478
- type Output<TOptions> = {
480
+ type Output<TOptions$1> = {
479
481
  /**
480
482
  * Path to the output folder or file that will contain the generated code
481
483
  */
@@ -488,11 +490,11 @@ type Output<TOptions> = {
488
490
  /**
489
491
  * Add a banner text in the beginning of every file
490
492
  */
491
- banner?: string | ((options: TOptions) => string);
493
+ banner?: string | ((options: TOptions$1) => string);
492
494
  /**
493
495
  * Add a footer text in the beginning of every file
494
496
  */
495
- footer?: string | ((options: TOptions) => string);
497
+ footer?: string | ((options: TOptions$1) => string);
496
498
  };
497
499
  type GroupContext = {
498
500
  group: string;
@@ -508,73 +510,19 @@ type Group = {
508
510
  name?: (context: GroupContext) => string;
509
511
  };
510
512
  //#endregion
511
- //#region ../core/src/FileManager.d.ts
512
- type FileMetaBase = {
513
- pluginKey?: Plugin['key'];
514
- };
515
- type AddResult<T extends Array<File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<ResolvedFile[]> : Promise<ResolvedFile>>>;
516
- type AddIndexesProps = {
517
- type: BarrelType | false | undefined;
518
- /**
519
- * Root based on root and output.path specified in the config
520
- */
521
- root: string;
522
- /**
523
- * Output for plugin
524
- */
525
- output: {
526
- path: string;
527
- };
528
- group?: {
529
- output: string;
530
- exportAs: string;
531
- };
532
- logger?: Logger;
533
- meta?: FileMetaBase;
534
- };
535
- type WriteFilesProps = {
536
- root: Config['root'];
537
- extension?: Record<Extname, Extname | ''>;
538
- logger?: Logger;
539
- dryRun?: boolean;
540
- };
541
- declare class FileManager {
542
- #private;
543
- constructor();
544
- add<T extends Array<File> = Array<File>>(...files: T): AddResult<T>;
545
- getByPath(path: Path): Promise<ResolvedFile | null>;
546
- deleteByPath(path: Path): Promise<void>;
547
- clear(): Promise<void>;
548
- getFiles(): Promise<Array<ResolvedFile>>;
549
- processFiles({
550
- dryRun,
551
- root,
552
- extension,
553
- logger
554
- }: WriteFilesProps): Promise<Array<ResolvedFile>>;
555
- getBarrelFiles({
556
- type,
557
- meta,
558
- root,
559
- output,
560
- logger
561
- }: AddIndexesProps): Promise<File[]>;
562
- static getMode(path: string | undefined | null): Mode;
563
- }
564
- //#endregion
565
513
  //#region ../core/src/PluginManager.d.ts
566
514
  type RequiredPluginLifecycle = Required<PluginLifecycle>;
567
515
  type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
568
- type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
516
+ type Executer<H$1 extends PluginLifecycleHooks = PluginLifecycleHooks> = {
569
517
  message: string;
570
518
  strategy: Strategy;
571
- hookName: H;
519
+ hookName: H$1;
572
520
  plugin: Plugin;
573
521
  parameters?: unknown[] | undefined;
574
522
  output?: unknown;
575
523
  };
576
- type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
577
- type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
524
+ type ParseResult<H$1 extends PluginLifecycleHooks> = RequiredPluginLifecycle[H$1];
525
+ type SafeParseResult<H$1 extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H$1>>> = {
578
526
  result: Result;
579
527
  plugin: Plugin;
580
528
  };
@@ -590,16 +538,19 @@ type Events = {
590
538
  executed: [executer: Executer];
591
539
  error: [error: Error];
592
540
  };
593
- type GetFileProps<TOptions = object> = {
541
+ type GetFileProps<TOptions$1 = object> = {
594
542
  name: string;
595
543
  mode?: Mode;
596
544
  extname: Extname;
597
545
  pluginKey: Plugin['key'];
598
- options?: TOptions;
546
+ options?: TOptions$1;
599
547
  };
600
548
  declare class PluginManager {
601
549
  #private;
602
550
  readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
551
+ /**
552
+ * @deprecated do not use from pluginManager
553
+ */
603
554
  readonly fileManager: FileManager;
604
555
  readonly events: EventEmitter<Events>;
605
556
  readonly config: Config;
@@ -708,6 +659,11 @@ declare class PluginManager {
708
659
  static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
709
660
  }
710
661
  //#endregion
662
+ //#region ../core/src/FileManager.d.ts
663
+ type FileMetaBase = {
664
+ pluginKey?: Plugin['key'];
665
+ };
666
+ //#endregion
711
667
  //#region ../plugin-oas/src/SchemaMapper.d.ts
712
668
  type SchemaKeywordMapper = {
713
669
  object: {
@@ -1001,12 +957,12 @@ type ByContentType = {
1001
957
  };
1002
958
  type Exclude$1 = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
1003
959
  type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
1004
- type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
1005
- options: Partial<TOptions>;
960
+ type Override<TOptions$1> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
961
+ options: Partial<TOptions$1>;
1006
962
  };
1007
963
  //#endregion
1008
964
  //#region ../plugin-oas/src/SchemaGenerator.d.ts
1009
- type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
965
+ type Context$1<TOptions$1, TPluginOptions extends PluginFactoryOptions> = {
1010
966
  oas: Oas;
1011
967
  pluginManager: PluginManager;
1012
968
  /**
@@ -1015,7 +971,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
1015
971
  plugin: Plugin<TPluginOptions>;
1016
972
  mode: Mode;
1017
973
  include?: Array<'schemas' | 'responses' | 'requestBodies'>;
1018
- override: Array<Override<TOptions>> | undefined;
974
+ override: Array<Override<TOptions$1>> | undefined;
1019
975
  contentType?: contentType;
1020
976
  output?: string;
1021
977
  };
@@ -1046,7 +1002,7 @@ type SchemaProps$1 = {
1046
1002
  name?: string;
1047
1003
  parentName?: string;
1048
1004
  };
1049
- declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions, Context$1<TOptions, TPluginOptions>> {
1005
+ declare class SchemaGenerator<TOptions$1 extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions$1, Context$1<TOptions$1, TPluginOptions>> {
1050
1006
  #private;
1051
1007
  refs: Refs;
1052
1008
  /**
@@ -1065,39 +1021,39 @@ declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGe
1065
1021
  }
1066
1022
  //#endregion
1067
1023
  //#region ../plugin-oas/src/generator.d.ts
1068
- type OperationsProps<TOptions extends PluginFactoryOptions> = {
1069
- instance: Omit<OperationGenerator<TOptions>, 'build'>;
1070
- options: TOptions['resolvedOptions'];
1024
+ type OperationsProps<TOptions$1 extends PluginFactoryOptions> = {
1025
+ instance: Omit<OperationGenerator<TOptions$1>, 'build'>;
1026
+ options: TOptions$1['resolvedOptions'];
1071
1027
  operations: Array<Operation$1>;
1072
1028
  };
1073
- type OperationProps<TOptions extends PluginFactoryOptions> = {
1074
- instance: Omit<OperationGenerator<TOptions>, 'build'>;
1075
- options: TOptions['resolvedOptions'];
1029
+ type OperationProps<TOptions$1 extends PluginFactoryOptions> = {
1030
+ instance: Omit<OperationGenerator<TOptions$1>, 'build'>;
1031
+ options: TOptions$1['resolvedOptions'];
1076
1032
  operation: Operation$1;
1077
1033
  };
1078
- type SchemaProps<TOptions extends PluginFactoryOptions> = {
1079
- instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
1080
- options: TOptions['resolvedOptions'];
1034
+ type SchemaProps<TOptions$1 extends PluginFactoryOptions> = {
1035
+ instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions$1>, 'build'>;
1036
+ options: TOptions$1['resolvedOptions'];
1081
1037
  schema: {
1082
1038
  name: string;
1083
1039
  tree: Array<Schema>;
1084
1040
  value: SchemaObject$1;
1085
1041
  };
1086
1042
  };
1087
- type GeneratorOptions<TOptions extends PluginFactoryOptions> = {
1043
+ type GeneratorOptions<TOptions$1 extends PluginFactoryOptions> = {
1088
1044
  name: string;
1089
- operations?: (this: GeneratorOptions<TOptions>, props: OperationsProps<TOptions>) => Promise<File[]>;
1090
- operation?: (this: GeneratorOptions<TOptions>, props: OperationProps<TOptions>) => Promise<File[]>;
1091
- schema?: (this: GeneratorOptions<TOptions>, props: SchemaProps<TOptions>) => Promise<File[]>;
1045
+ operations?: (this: GeneratorOptions<TOptions$1>, props: OperationsProps<TOptions$1>) => Promise<File[]>;
1046
+ operation?: (this: GeneratorOptions<TOptions$1>, props: OperationProps<TOptions$1>) => Promise<File[]>;
1047
+ schema?: (this: GeneratorOptions<TOptions$1>, props: SchemaProps<TOptions$1>) => Promise<File[]>;
1092
1048
  };
1093
- type Generator<TOptions extends PluginFactoryOptions> = GeneratorOptions<TOptions>;
1049
+ type Generator<TOptions$1 extends PluginFactoryOptions> = GeneratorOptions<TOptions$1>;
1094
1050
  //#endregion
1095
1051
  //#region ../plugin-oas/src/OperationGenerator.d.ts
1096
- type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
1052
+ type Context<TOptions$1, TPluginOptions extends PluginFactoryOptions> = {
1097
1053
  oas: Oas;
1098
1054
  exclude: Array<Exclude$1> | undefined;
1099
1055
  include: Array<Include> | undefined;
1100
- override: Array<Override<TOptions>> | undefined;
1056
+ override: Array<Override<TOptions$1>> | undefined;
1101
1057
  contentType: contentType | undefined;
1102
1058
  pluginManager: PluginManager;
1103
1059
  /**
@@ -1181,5 +1137,5 @@ type ResolvedOptions = {
1181
1137
  };
1182
1138
  type PluginMsw = PluginFactoryOptions<'plugin-msw', Options$1, ResolvedOptions, never, ResolvePathOptions>;
1183
1139
  //#endregion
1184
- export { Generator, Options$1 as Options, PluginMsw, UserPluginWithLifeCycle };
1185
- //# sourceMappingURL=types-DLxzBV0T.d.cts.map
1140
+ export { UserPluginWithLifeCycle as i, PluginMsw as n, Generator as r, Options$1 as t };
1141
+ //# sourceMappingURL=types-BLiYk9M7.d.ts.map
@@ -9,5 +9,5 @@ type SchemaObject$1 = OasTypes.SchemaObject & {
9
9
  $ref?: string;
10
10
  };
11
11
  //#endregion
12
- export { type HttpMethod, type OasTypes, type Operation$1 as Operation, SchemaObject$1 as SchemaObject, contentType };
13
- //# sourceMappingURL=types-DYAniEBx.d.cts.map
12
+ export { contentType as a, SchemaObject$1 as i, OasTypes as n, Operation$1 as r, HttpMethod as t };
13
+ //# sourceMappingURL=types-IbHKcY02.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-msw",
3
- "version": "4.1.4",
3
+ "version": "4.2.1",
4
4
  "description": "Mock Service Worker (MSW) handlers generator plugin for Kubb, creating API mocks from OpenAPI specifications for frontend development and testing.",
5
5
  "keywords": [
6
6
  "msw",
@@ -66,17 +66,15 @@
66
66
  "!/**/__tests__/**"
67
67
  ],
68
68
  "dependencies": {
69
- "@kubb/core": "4.1.4",
70
- "@kubb/oas": "4.1.4",
71
- "@kubb/plugin-faker": "4.1.4",
72
- "@kubb/plugin-oas": "4.1.4",
73
- "@kubb/plugin-ts": "4.1.4",
74
- "@kubb/react": "4.1.4"
69
+ "@kubb/core": "4.2.1",
70
+ "@kubb/oas": "4.2.1",
71
+ "@kubb/plugin-faker": "4.2.1",
72
+ "@kubb/plugin-oas": "4.2.1",
73
+ "@kubb/plugin-ts": "4.2.1",
74
+ "@kubb/react": "4.2.1"
75
75
  },
76
76
  "devDependencies": {
77
- "@types/react": "^18.3.26",
78
- "react": "^18.3.1",
79
- "tsdown": "^0.14.2",
77
+ "tsdown": "^0.15.9",
80
78
  "typescript": "^5.9.3"
81
79
  },
82
80
  "peerDependencies": {
@@ -1,5 +1,4 @@
1
1
  import { File } from '@kubb/react'
2
- import type { ReactNode } from 'react'
3
2
 
4
3
  type HandlersProps = {
5
4
  /**
@@ -10,7 +9,7 @@ type HandlersProps = {
10
9
  handlers: string[]
11
10
  }
12
11
 
13
- export function Handlers({ name, handlers }: HandlersProps): ReactNode {
12
+ export function Handlers({ name, handlers }: HandlersProps) {
14
13
  return (
15
14
  <File.Source name={name} isIndexable isExportable>
16
15
  {`export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, '')} as const`}
@@ -1,7 +1,6 @@
1
1
  import { URLPath } from '@kubb/core/utils'
2
2
  import type { OasTypes, Operation } from '@kubb/oas'
3
3
  import { File, Function, FunctionParams } from '@kubb/react'
4
- import type { ReactNode } from 'react'
5
4
 
6
5
  type Props = {
7
6
  /**
@@ -14,7 +13,7 @@ type Props = {
14
13
  operation: Operation
15
14
  }
16
15
 
17
- export function Mock({ baseURL = '', name, typeName, operation }: Props): ReactNode {
16
+ export function Mock({ baseURL = '', name, typeName, operation }: Props) {
18
17
  const method = operation.method
19
18
  const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith('2'))
20
19
  const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200
@@ -2,7 +2,6 @@ import { URLPath } from '@kubb/core/utils'
2
2
 
3
3
  import type { OasTypes, Operation } from '@kubb/oas'
4
4
  import { File, Function, FunctionParams } from '@kubb/react'
5
- import type { ReactNode } from 'react'
6
5
 
7
6
  type Props = {
8
7
  /**
@@ -15,7 +14,7 @@ type Props = {
15
14
  operation: Operation
16
15
  }
17
16
 
18
- export function MockWithFaker({ baseURL = '', name, fakerName, typeName, operation }: Props): ReactNode {
17
+ export function MockWithFaker({ baseURL = '', name, fakerName, typeName, operation }: Props) {
19
18
  const method = operation.method
20
19
  const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith('2'))
21
20
  const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200
@@ -0,0 +1,42 @@
1
+ import type { OasTypes, Operation } from '@kubb/oas'
2
+ import { File, Function, FunctionParams } from '@kubb/react'
3
+
4
+ type Props = {
5
+ typeName: string
6
+ operation: Operation
7
+ name: string
8
+ statusCode: number
9
+ }
10
+
11
+ export function Response({ name, typeName, operation, statusCode }: Props) {
12
+ const responseObject = operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject
13
+ const contentType = Object.keys(responseObject.content || {})?.[0]
14
+
15
+ const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)
16
+
17
+ const params = FunctionParams.factory({
18
+ data: {
19
+ type: `${typeName}`,
20
+ },
21
+ })
22
+
23
+ const responseName = `${name}Response${statusCode}`
24
+
25
+ return (
26
+ <File.Source name={responseName} isIndexable isExportable>
27
+ <Function name={responseName} export params={params.toConstructor()}>
28
+ {`
29
+ return new Response(JSON.stringify(data), {
30
+ status: ${statusCode},
31
+ ${
32
+ headers.length
33
+ ? ` headers: {
34
+ ${headers.join(', \n')}
35
+ },`
36
+ : ''
37
+ }
38
+ })`}
39
+ </Function>
40
+ </File.Source>
41
+ )
42
+ }
@@ -1,3 +1,4 @@
1
1
  export { Mock } from './Mock.tsx'
2
2
  export { Handlers } from './Handlers.tsx'
3
3
  export { MockWithFaker } from './MockWithFaker.tsx'
4
+ export { Response } from './Response.tsx'
@@ -4,6 +4,12 @@
4
4
  */
5
5
  import { http } from 'msw'
6
6
 
7
+ export function createPetsResponse201(data: CreatePetsMutationResponse) {
8
+ return new Response(JSON.stringify(data), {
9
+ status: 201,
10
+ })
11
+ }
12
+
7
13
  export function createPets(data?: CreatePetsMutationResponse | ((info: Parameters<Parameters<typeof http.post>[1]>[0]) => Response | Promise<Response>)) {
8
14
  return http.post('/pets', function handler(info) {
9
15
  if (typeof data === 'function') return data(info)
@@ -4,6 +4,12 @@
4
4
  */
5
5
  import { http } from 'msw'
6
6
 
7
+ export function createPetsResponse201(data: CreatePetsMutationResponse) {
8
+ return new Response(JSON.stringify(data), {
9
+ status: 201,
10
+ })
11
+ }
12
+
7
13
  export function createPets(data?: CreatePetsMutationResponse | ((info: Parameters<Parameters<typeof http.post>[1]>[0]) => Response | Promise<Response>)) {
8
14
  return http.post('/pets', function handler(info) {
9
15
  if (typeof data === 'function') return data(info)
@@ -4,6 +4,21 @@
4
4
  */
5
5
  import { http } from 'msw'
6
6
 
7
+ export function listPetsResponse200(data: ListPetsQueryResponse) {
8
+ return new Response(JSON.stringify(data), {
9
+ status: 200,
10
+ headers: {
11
+ 'Content-Type': 'application/json',
12
+ },
13
+ })
14
+ }
15
+
16
+ export function listPetsResponse400(data: ListPets400) {
17
+ return new Response(JSON.stringify(data), {
18
+ status: 400,
19
+ })
20
+ }
21
+
7
22
  export function listPets(data?: ListPetsQueryResponse | ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Response | Promise<Response>)) {
8
23
  return http.get('/pets', function handler(info) {
9
24
  if (typeof data === 'function') return data(info)
@@ -4,6 +4,21 @@
4
4
  */
5
5
  import { http } from 'msw'
6
6
 
7
+ export function listPetsResponse200(data: ListPetsQueryResponse) {
8
+ return new Response(JSON.stringify(data), {
9
+ status: 200,
10
+ headers: {
11
+ 'Content-Type': 'application/json',
12
+ },
13
+ })
14
+ }
15
+
16
+ export function listPetsResponse400(data: ListPets400) {
17
+ return new Response(JSON.stringify(data), {
18
+ status: 400,
19
+ })
20
+ }
21
+
7
22
  export function listPets(data?: ListPetsQueryResponse | ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Response | Promise<Response>)) {
8
23
  return http.get('/pets', function handler(info) {
9
24
  if (typeof data === 'function') return data(info)