@kubb/plugin-msw 5.0.0-beta.31 → 5.0.0-beta.33

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 (2) hide show
  1. package/extension.yaml +97 -25
  2. package/package.json +6 -6
package/extension.yaml CHANGED
@@ -333,31 +333,6 @@ options:
333
333
  import { handlersGet, handlersPost } from './gen/handlers'
334
334
 
335
335
  export const server = setupServer(...handlersGet, ...handlersPost)
336
- - name: contentType
337
- type: "'application/json' | (string & {})"
338
- required: false
339
- description: |
340
- Selects which request/response media type the generator reads from the OpenAPI spec.
341
-
342
- When omitted, Kubb picks the first JSON-compatible media type it finds (`application/json`, `application/vnd.api+json`, anything ending in `+json`). Set this when your spec defines multiple media types for the same operation and you want a non-default one.
343
- examples:
344
- - name: JSON API media type
345
- files:
346
- - lang: typescript
347
- twoslash: false
348
- code: |
349
- import { defineConfig } from 'kubb'
350
- import { pluginTs } from '@kubb/plugin-ts'
351
-
352
- export default defineConfig({
353
- input: { path: './petStore.yaml' },
354
- output: { path: './src/gen' },
355
- plugins: [
356
- pluginTs({
357
- contentType: 'application/vnd.api+json',
358
- }),
359
- ],
360
- })
361
336
  - name: baseURL
362
337
  type: string
363
338
  required: false
@@ -653,6 +628,103 @@ options:
653
628
  Use this when you need output the plugin does not produce out of the box (a custom client wrapper, an extra index, a metadata file). For end-to-end guidance, see [Creating plugins](https://kubb.dev/docs/5.x/guides/creating-plugins).
654
629
  warning: |
655
630
  Generators are an experimental, low-level API. The signature may change between minor releases.
631
+ - name: resolver
632
+ type: Partial<ResolverMsw> & ThisType<ResolverMsw>
633
+ required: false
634
+ description: |
635
+ Overrides how the plugin builds names and paths for generated files and symbols. Use this to add prefixes, suffixes, or to swap the casing strategy without forking the plugin.
636
+
637
+ Only override the methods you want to change. Anything you omit falls back to the plugin's default resolver. A method that returns `null` or `undefined` also falls back.
638
+
639
+ Inside each method, `this` is bound to the full resolver, so you can call `this.default(name, 'function')` to delegate to the built-in implementation.
640
+ body: |
641
+ Each plugin ships with a default resolver:
642
+
643
+ | Plugin | Default resolver |
644
+ | --- | --- |
645
+ | `@kubb/plugin-ts` | `resolverTs` |
646
+ | `@kubb/plugin-zod` | `resolverZod` |
647
+ | `@kubb/plugin-faker` | `resolverFaker` |
648
+ | `@kubb/plugin-cypress` | `resolverCypress` |
649
+ | `@kubb/plugin-msw` | `resolverMsw` |
650
+ | `@kubb/plugin-mcp` | `resolverMcp` |
651
+ | `@kubb/plugin-client` | `resolverClient` |
652
+ codeBlock:
653
+ lang: typescript
654
+ title: Prefix every handler name with "Mock"
655
+ code: |
656
+ import { defineConfig } from 'kubb'
657
+ import { pluginMsw } from '@kubb/plugin-msw'
658
+
659
+ export default defineConfig({
660
+ input: { path: './petStore.yaml' },
661
+ output: { path: './src/gen' },
662
+ plugins: [
663
+ pluginMsw({
664
+ resolver: {
665
+ resolveName(name) {
666
+ return `Mock${this.default(name, 'function')}`
667
+ },
668
+ },
669
+ }),
670
+ ],
671
+ })
672
+ tip: |
673
+ Use `resolver` for naming and file-location tweaks. For changing the AST nodes themselves (e.g. stripping descriptions), use `transformer` instead.
674
+ - name: transformer
675
+ type: Visitor
676
+ required: false
677
+ description: |
678
+ Modifies AST nodes before they are printed to source code. Use this when you need to rewrite operation IDs, drop descriptions, or change schema metadata without forking the generator.
679
+
680
+ Each visitor method (e.g. `schema`, `operation`) receives the node and a context object. Return a new node to replace it, or return `undefined` to leave it untouched. Methods you omit keep the plugin's default behavior.
681
+ examples:
682
+ - name: Strip descriptions before printing
683
+ files:
684
+ - name: kubb.config.ts
685
+ lang: typescript
686
+ twoslash: false
687
+ code: |
688
+ import { defineConfig } from 'kubb'
689
+ import { pluginTs } from '@kubb/plugin-ts'
690
+
691
+ export default defineConfig({
692
+ input: { path: './petStore.yaml' },
693
+ output: { path: './src/gen' },
694
+ plugins: [
695
+ pluginTs({
696
+ transformer: {
697
+ schema(node) {
698
+ return { ...node, description: undefined }
699
+ },
700
+ },
701
+ }),
702
+ ],
703
+ })
704
+ - name: Prefix every operationId
705
+ files:
706
+ - name: kubb.config.ts
707
+ lang: typescript
708
+ twoslash: false
709
+ code: |
710
+ import { defineConfig } from 'kubb'
711
+ import { pluginTs } from '@kubb/plugin-ts'
712
+
713
+ export default defineConfig({
714
+ input: { path: './petStore.yaml' },
715
+ output: { path: './src/gen' },
716
+ plugins: [
717
+ pluginTs({
718
+ transformer: {
719
+ operation(node) {
720
+ return { ...node, operationId: `api_${node.operationId}` }
721
+ },
722
+ },
723
+ }),
724
+ ],
725
+ })
726
+ tip: |
727
+ Use `transformer` to rewrite node properties before printing. For changing the names of generated symbols and files, use `resolver` instead.
656
728
  examples:
657
729
  - name: kubb.config.ts
658
730
  files:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-msw",
3
- "version": "5.0.0-beta.31",
3
+ "version": "5.0.0-beta.33",
4
4
  "description": "Generate Mock Service Worker (MSW) request handlers from your OpenAPI specification. Intercept HTTP requests in the browser or Node.js for seamless frontend development and testing.",
5
5
  "keywords": [
6
6
  "api-mocking",
@@ -72,17 +72,17 @@
72
72
  "registry": "https://registry.npmjs.org/"
73
73
  },
74
74
  "dependencies": {
75
- "@kubb/core": "5.0.0-beta.31",
76
- "@kubb/renderer-jsx": "5.0.0-beta.31",
77
- "@kubb/plugin-faker": "5.0.0-beta.31",
78
- "@kubb/plugin-ts": "5.0.0-beta.31"
75
+ "@kubb/core": "5.0.0-beta.33",
76
+ "@kubb/renderer-jsx": "5.0.0-beta.33",
77
+ "@kubb/plugin-faker": "5.0.0-beta.33",
78
+ "@kubb/plugin-ts": "5.0.0-beta.33"
79
79
  },
80
80
  "devDependencies": {
81
81
  "@internals/shared": "0.0.0",
82
82
  "@internals/utils": "0.0.0"
83
83
  },
84
84
  "peerDependencies": {
85
- "@kubb/renderer-jsx": "5.0.0-beta.31"
85
+ "@kubb/renderer-jsx": "5.0.0-beta.33"
86
86
  },
87
87
  "size-limit": [
88
88
  {