@kubb/plugin-msw 3.16.2 → 3.16.3

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 (47) hide show
  1. package/dist/components-ByUOezvw.js +93 -0
  2. package/dist/components-ByUOezvw.js.map +1 -0
  3. package/dist/components-Bz0C7Qrg.cjs +139 -0
  4. package/dist/components-Bz0C7Qrg.cjs.map +1 -0
  5. package/dist/components.cjs +4 -19
  6. package/dist/components.d.cts +47 -33
  7. package/dist/components.d.ts +47 -33
  8. package/dist/components.js +3 -3
  9. package/dist/generators-BjQcx0SS.js +140 -0
  10. package/dist/generators-BjQcx0SS.js.map +1 -0
  11. package/dist/generators-DQ6KjdAH.cjs +151 -0
  12. package/dist/generators-DQ6KjdAH.cjs.map +1 -0
  13. package/dist/generators.cjs +4 -16
  14. package/dist/generators.d.cts +9 -8
  15. package/dist/generators.d.ts +9 -8
  16. package/dist/generators.js +4 -4
  17. package/dist/index.cjs +82 -102
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +7 -7
  20. package/dist/index.d.ts +7 -7
  21. package/dist/index.js +82 -96
  22. package/dist/index.js.map +1 -1
  23. package/dist/types-BOMj2hjt.d.ts +13 -0
  24. package/dist/types-CxxnBHOU.d.cts +1164 -0
  25. package/dist/types-DYAniEBx.d.cts +13 -0
  26. package/dist/types-Dte4R-vh.d.ts +1164 -0
  27. package/package.json +19 -34
  28. package/src/components/Mock.tsx +21 -9
  29. package/src/components/MockWithFaker.tsx +22 -9
  30. package/src/generators/__snapshots__/createPet.ts +0 -3
  31. package/src/generators/__snapshots__/createPetFaker.ts +0 -3
  32. package/src/generators/__snapshots__/deletePet.ts +0 -3
  33. package/src/generators/mswGenerator.tsx +2 -16
  34. package/dist/chunk-6ANKBOX6.cjs +0 -113
  35. package/dist/chunk-6ANKBOX6.cjs.map +0 -1
  36. package/dist/chunk-FYUFQXX6.cjs +0 -55
  37. package/dist/chunk-FYUFQXX6.cjs.map +0 -1
  38. package/dist/chunk-GUSADLEP.js +0 -110
  39. package/dist/chunk-GUSADLEP.js.map +0 -1
  40. package/dist/chunk-HL53J5NZ.js +0 -51
  41. package/dist/chunk-HL53J5NZ.js.map +0 -1
  42. package/dist/components.cjs.map +0 -1
  43. package/dist/components.js.map +0 -1
  44. package/dist/generators.cjs.map +0 -1
  45. package/dist/generators.js.map +0 -1
  46. package/dist/types-CzI_io_g.d.cts +0 -64
  47. package/dist/types-CzI_io_g.d.ts +0 -64
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-msw",
3
- "version": "3.16.2",
3
+ "version": "3.16.3",
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",
@@ -28,35 +28,21 @@
28
28
  "exports": {
29
29
  ".": {
30
30
  "import": "./dist/index.js",
31
- "require": "./dist/index.cjs",
32
- "default": "./dist/index.cjs"
33
- },
34
- "./utils": {
35
- "import": "./dist/utils.js",
36
- "require": "./dist/utils.cjs",
37
- "default": "./dist/utils.cjs"
38
- },
39
- "./hooks": {
40
- "import": "./dist/hooks.js",
41
- "require": "./dist/hooks.cjs",
42
- "default": "./dist/hooks.cjs"
31
+ "require": "./dist/index.cjs"
43
32
  },
44
33
  "./components": {
45
34
  "import": "./dist/components.js",
46
- "require": "./dist/components.cjs",
47
- "default": "./dist/components.cjs"
35
+ "require": "./dist/components.cjs"
48
36
  },
49
37
  "./generators": {
50
38
  "import": "./dist/generators.js",
51
- "require": "./dist/generators.cjs",
52
- "default": "./dist/generators.cjs"
39
+ "require": "./dist/generators.cjs"
53
40
  },
54
- "./package.json": "./package.json",
55
- "./*": "./*"
41
+ "./package.json": "./package.json"
56
42
  },
57
- "main": "dist/index.cjs",
58
- "module": "dist/index.js",
59
- "types": "./dist/index.d.ts",
43
+ "main": "./dist/index.cjs",
44
+ "module": "./dist/index.js",
45
+ "types": "./dist/index.d.cts",
60
46
  "typesVersions": {
61
47
  "*": {
62
48
  "utils": [
@@ -80,20 +66,19 @@
80
66
  "!/**/__tests__/**"
81
67
  ],
82
68
  "dependencies": {
83
- "@kubb/core": "3.16.2",
84
- "@kubb/oas": "3.16.2",
85
- "@kubb/plugin-oas": "3.16.2",
86
- "@kubb/plugin-faker": "3.16.2",
87
- "@kubb/plugin-ts": "3.16.2",
88
- "@kubb/react": "3.16.2"
69
+ "@kubb/core": "3.16.3",
70
+ "@kubb/oas": "3.16.3",
71
+ "@kubb/plugin-faker": "3.16.3",
72
+ "@kubb/plugin-oas": "3.16.3",
73
+ "@kubb/plugin-ts": "3.16.3",
74
+ "@kubb/react": "3.16.3"
89
75
  },
90
76
  "devDependencies": {
91
77
  "@types/react": "^18.3.23",
92
78
  "react": "^18.3.1",
93
- "tsup": "^8.5.0",
79
+ "tsdown": "^0.14.1",
94
80
  "typescript": "^5.9.2",
95
- "@kubb/config-ts": "3.16.2",
96
- "@kubb/config-tsup": "3.16.2"
81
+ "@kubb/config-ts": "3.16.3"
97
82
  },
98
83
  "peerDependencies": {
99
84
  "@kubb/react": "^3.0.0"
@@ -106,13 +91,13 @@
106
91
  "registry": "https://registry.npmjs.org/"
107
92
  },
108
93
  "scripts": {
109
- "build": "tsup",
94
+ "build": "tsdown",
110
95
  "clean": "npx rimraf ./dist",
111
96
  "lint": "bun biome lint .",
112
- "lint:fix": "bun biome lint--fix --unsafe .",
97
+ "lint:fix": "bun biome lint --fix --unsafe .",
113
98
  "release": "pnpm publish --no-git-check",
114
99
  "release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
115
- "start": "tsup --watch",
100
+ "start": "tsdown --watch",
116
101
  "test": "vitest --passWithNoTests",
117
102
  "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
118
103
  }
@@ -1,6 +1,6 @@
1
+ import { URLPath } from '@kubb/core/utils'
2
+ import type { OasTypes, Operation } from '@kubb/oas'
1
3
  import { File, Function, FunctionParams } from '@kubb/react'
2
-
3
- import type { HttpMethod } from '@kubb/oas'
4
4
  import type { ReactNode } from 'react'
5
5
 
6
6
  type Props = {
@@ -10,13 +10,21 @@ type Props = {
10
10
  name: string
11
11
  typeName: string
12
12
  fakerName: string
13
- url: string
14
13
  baseURL: string | undefined
15
- method: HttpMethod
16
- statusCode: number
14
+ operation: Operation
17
15
  }
18
16
 
19
- export function Mock({ baseURL = '', name, typeName, url, method, statusCode }: Props): ReactNode {
17
+ export function Mock({ baseURL = '', name, typeName, operation }: Props): ReactNode {
18
+ const method = operation.method
19
+ const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith('2'))
20
+ const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200
21
+
22
+ const responseObject = operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject
23
+ const contentType = Object.keys(responseObject.content || {})?.[0]
24
+ const url = new URLPath(operation.path).toURLPath().replace(/([^/]):/g, '$1\\\\:')
25
+
26
+ const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)
27
+
20
28
  const params = FunctionParams.factory({
21
29
  data: {
22
30
  type: `${typeName} | ((
@@ -34,9 +42,13 @@ export function Mock({ baseURL = '', name, typeName, url, method, statusCode }:
34
42
 
35
43
  return new Response(JSON.stringify(data), {
36
44
  status: ${statusCode},
37
- headers: {
38
- 'Content-Type': 'application/json',
39
- },
45
+ ${
46
+ headers.length
47
+ ? ` headers: {
48
+ ${headers.join(', \n')}
49
+ },`
50
+ : ''
51
+ }
40
52
  })
41
53
  })`}
42
54
  </Function>
@@ -1,6 +1,7 @@
1
- import { File, Function, FunctionParams } from '@kubb/react'
1
+ import { URLPath } from '@kubb/core/utils'
2
2
 
3
- import type { HttpMethod } from '@kubb/oas'
3
+ import type { OasTypes, Operation } from '@kubb/oas'
4
+ import { File, Function, FunctionParams } from '@kubb/react'
4
5
  import type { ReactNode } from 'react'
5
6
 
6
7
  type Props = {
@@ -11,12 +12,20 @@ type Props = {
11
12
  typeName: string
12
13
  fakerName: string
13
14
  baseURL: string | undefined
14
- url: string
15
- method: HttpMethod
16
- statusCode: number
15
+ operation: Operation
17
16
  }
18
17
 
19
- export function MockWithFaker({ baseURL = '', name, fakerName, typeName, url, method, statusCode }: Props): ReactNode {
18
+ export function MockWithFaker({ baseURL = '', name, fakerName, typeName, operation }: Props): ReactNode {
19
+ const method = operation.method
20
+ const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith('2'))
21
+ const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200
22
+
23
+ const responseObject = operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject
24
+ const contentType = Object.keys(responseObject.content || {})?.[0]
25
+ const url = new URLPath(operation.path).toURLPath().replace(/([^/]):/g, '$1\\\\:')
26
+
27
+ const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)
28
+
20
29
  const params = FunctionParams.factory({
21
30
  data: {
22
31
  type: `${typeName} | ((
@@ -34,9 +43,13 @@ export function MockWithFaker({ baseURL = '', name, fakerName, typeName, url, me
34
43
 
35
44
  return new Response(JSON.stringify(data || ${fakerName}(data)), {
36
45
  status: ${statusCode},
37
- headers: {
38
- 'Content-Type': 'application/json',
39
- },
46
+ ${
47
+ headers.length
48
+ ? ` headers: {
49
+ ${headers.join(', \n')}
50
+ },`
51
+ : ''
52
+ }
40
53
  })
41
54
  })`}
42
55
  </Function>
@@ -10,9 +10,6 @@ export function createPets(data?: CreatePetsMutationResponse | ((info: Parameter
10
10
 
11
11
  return new Response(JSON.stringify(data), {
12
12
  status: 201,
13
- headers: {
14
- 'Content-Type': 'application/json',
15
- },
16
13
  })
17
14
  })
18
15
  }
@@ -10,9 +10,6 @@ export function createPets(data?: CreatePetsMutationResponse | ((info: Parameter
10
10
 
11
11
  return new Response(JSON.stringify(data || createPetsMutationResponse(data)), {
12
12
  status: 201,
13
- headers: {
14
- 'Content-Type': 'application/json',
15
- },
16
13
  })
17
14
  })
18
15
  }
@@ -10,9 +10,6 @@ export function deletePetsPetid(data?: DeletePetsPetidMutationResponse | ((info:
10
10
 
11
11
  return new Response(JSON.stringify(data), {
12
12
  status: 200,
13
- headers: {
14
- 'Content-Type': 'application/json',
15
- },
16
13
  })
17
14
  })
18
15
  }
@@ -1,4 +1,3 @@
1
- import { URLPath } from '@kubb/core/utils'
2
1
  import { pluginFakerName } from '@kubb/plugin-faker'
3
2
  import { createReactGenerator } from '@kubb/plugin-oas'
4
3
  import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
@@ -35,9 +34,6 @@ export const mswGenerator = createReactGenerator<PluginMsw>({
35
34
  schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
36
35
  }
37
36
 
38
- const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith('2'))
39
- const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200
40
-
41
37
  return (
42
38
  <File
43
39
  baseName={mock.file.baseName}
@@ -58,22 +54,12 @@ export const mswGenerator = createReactGenerator<PluginMsw>({
58
54
  name={mock.name}
59
55
  typeName={type.schemas.response.name}
60
56
  fakerName={faker.schemas.response.name}
61
- method={operation.method}
57
+ operation={operation}
62
58
  baseURL={baseURL}
63
- url={new URLPath(operation.path).toURLPath().replace(/([^/]):/g, '$1\\\\:')}
64
- statusCode={statusCode}
65
59
  />
66
60
  )}
67
61
  {parser === 'data' && (
68
- <Mock
69
- name={mock.name}
70
- typeName={type.schemas.response.name}
71
- fakerName={faker.schemas.response.name}
72
- method={operation.method}
73
- baseURL={baseURL}
74
- url={new URLPath(operation.path).toURLPath().replace(/([^/]):/g, '$1\\\\:')}
75
- statusCode={statusCode}
76
- />
62
+ <Mock name={mock.name} typeName={type.schemas.response.name} fakerName={faker.schemas.response.name} operation={operation} baseURL={baseURL} />
77
63
  )}
78
64
  </File>
79
65
  )
@@ -1,113 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkFYUFQXX6_cjs = require('./chunk-FYUFQXX6.cjs');
4
- var utils$1 = require('@kubb/core/utils');
5
- var pluginFaker = require('@kubb/plugin-faker');
6
- var pluginOas = require('@kubb/plugin-oas');
7
- var hooks = require('@kubb/plugin-oas/hooks');
8
- var utils = require('@kubb/plugin-oas/utils');
9
- var pluginTs = require('@kubb/plugin-ts');
10
- var react = require('@kubb/react');
11
- var jsxRuntime = require('@kubb/react/jsx-runtime');
12
-
13
- var mswGenerator = pluginOas.createReactGenerator({
14
- name: "msw",
15
- Operation({ operation }) {
16
- const {
17
- pluginManager,
18
- plugin: {
19
- options: { output, parser, baseURL }
20
- }
21
- } = react.useApp();
22
- const oas = hooks.useOas();
23
- const { getSchemas, getName, getFile } = hooks.useOperationManager();
24
- const mock = {
25
- name: getName(operation, { type: "function" }),
26
- file: getFile(operation)
27
- };
28
- const faker = {
29
- file: getFile(operation, { pluginKey: [pluginFaker.pluginFakerName] }),
30
- schemas: getSchemas(operation, { pluginKey: [pluginFaker.pluginFakerName], type: "function" })
31
- };
32
- const type = {
33
- file: getFile(operation, { pluginKey: [pluginTs.pluginTsName] }),
34
- schemas: getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" })
35
- };
36
- const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith("2"));
37
- const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200;
38
- return /* @__PURE__ */ jsxRuntime.jsxs(
39
- react.File,
40
- {
41
- baseName: mock.file.baseName,
42
- path: mock.file.path,
43
- meta: mock.file.meta,
44
- banner: utils.getBanner({ oas, output, config: pluginManager.config }),
45
- footer: utils.getFooter({ oas, output }),
46
- children: [
47
- /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["http"], path: "msw" }),
48
- /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["ResponseResolver"], isTypeOnly: true, path: "msw" }),
49
- /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [type.schemas.response.name], path: type.file.path, root: mock.file.path, isTypeOnly: true }),
50
- parser === "faker" && faker.file && faker.schemas.response && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [faker.schemas.response.name], root: mock.file.path, path: faker.file.path }),
51
- parser === "faker" && /* @__PURE__ */ jsxRuntime.jsx(
52
- chunkFYUFQXX6_cjs.MockWithFaker,
53
- {
54
- name: mock.name,
55
- typeName: type.schemas.response.name,
56
- fakerName: faker.schemas.response.name,
57
- method: operation.method,
58
- baseURL,
59
- url: new utils$1.URLPath(operation.path).toURLPath().replace(/([^/]):/g, "$1\\\\:"),
60
- statusCode
61
- }
62
- ),
63
- parser === "data" && /* @__PURE__ */ jsxRuntime.jsx(
64
- chunkFYUFQXX6_cjs.Mock,
65
- {
66
- name: mock.name,
67
- typeName: type.schemas.response.name,
68
- fakerName: faker.schemas.response.name,
69
- method: operation.method,
70
- baseURL,
71
- url: new utils$1.URLPath(operation.path).toURLPath().replace(/([^/]):/g, "$1\\\\:"),
72
- statusCode
73
- }
74
- )
75
- ]
76
- }
77
- );
78
- }
79
- });
80
- var handlersGenerator = pluginOas.createReactGenerator({
81
- name: "plugin-msw",
82
- Operations({ operations }) {
83
- const { pluginManager, plugin } = react.useApp();
84
- const oas = hooks.useOas();
85
- const { getName, getFile } = hooks.useOperationManager();
86
- const file = pluginManager.getFile({ name: "handlers", extname: ".ts", pluginKey: plugin.key });
87
- const imports = operations.map((operation) => {
88
- const operationFile = getFile(operation, { pluginKey: plugin.key });
89
- const operationName = getName(operation, { pluginKey: plugin.key, type: "function" });
90
- return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
91
- });
92
- const handlers = operations.map((operation) => `${getName(operation, { type: "function", pluginKey: plugin.key })}()`);
93
- return /* @__PURE__ */ jsxRuntime.jsxs(
94
- react.File,
95
- {
96
- baseName: file.baseName,
97
- path: file.path,
98
- meta: file.meta,
99
- banner: utils.getBanner({ oas, output: plugin.options.output, config: pluginManager.config }),
100
- footer: utils.getFooter({ oas, output: plugin.options.output }),
101
- children: [
102
- imports,
103
- /* @__PURE__ */ jsxRuntime.jsx(chunkFYUFQXX6_cjs.Handlers, { name: "handlers", handlers })
104
- ]
105
- }
106
- );
107
- }
108
- });
109
-
110
- exports.handlersGenerator = handlersGenerator;
111
- exports.mswGenerator = mswGenerator;
112
- //# sourceMappingURL=chunk-6ANKBOX6.cjs.map
113
- //# sourceMappingURL=chunk-6ANKBOX6.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/generators/mswGenerator.tsx","../src/generators/handlersGenerator.tsx"],"names":["createReactGenerator","useApp","useOas","useOperationManager","pluginFakerName","pluginTsName","jsxs","File","getBanner","getFooter","jsx","MockWithFaker","URLPath","Mock","Handlers"],"mappings":";;;;;;;;;;;;AAUO,IAAM,eAAeA,8BAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,MACJ,aAAA;AAAA,MACA,MAAQ,EAAA;AAAA,QACN,OAAS,EAAA,EAAE,MAAQ,EAAA,MAAA,EAAQ,OAAQ;AAAA;AACrC,QACEC,YAAkB,EAAA;AACtB,IAAA,MAAM,MAAMC,YAAO,EAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAYC,yBAAoB,EAAA;AAE7D,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7C,IAAA,EAAM,QAAQ,SAAS;AAAA,KACzB;AAEA,IAAA,MAAM,KAAQ,GAAA;AAAA,MACZ,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAACC,2BAAe,GAAG,CAAA;AAAA,MACzD,OAAA,EAAS,UAAW,CAAA,SAAA,EAAW,EAAE,SAAA,EAAW,CAACA,2BAAe,CAAA,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Y,SAAW,EAAA,MAAA,CAAO,GAAI,EAAC,CAAC,CAAI,EAAA,CAAA,CAAA;AAErH,IAAA,uBACED,eAAAA;AAAA,MAACC,UAAAA;AAAA,MAAA;AAAA,QACC,UAAU,IAAK,CAAA,QAAA;AAAA,QACf,MAAM,IAAK,CAAA,IAAA;AAAA,QACX,MAAM,IAAK,CAAA,IAAA;AAAA,QACX,MAAA,EAAQC,eAAU,CAAA,EAAE,GAAK,EAAA,MAAA,EAAQ,MAAO,CAAA,OAAA,CAAQ,MAAQ,EAAA,MAAA,EAAQ,aAAc,CAAA,MAAA,EAAQ,CAAA;AAAA,QACtF,MAAA,EAAQC,gBAAU,EAAE,GAAA,EAAK,QAAQ,MAAO,CAAA,OAAA,CAAQ,QAAQ,CAAA;AAAA,QAEvD,QAAA,EAAA;AAAA,UAAA,OAAA;AAAA,0BACDC,cAAAA,CAACI,0BAAS,EAAA,EAAA,IAAA,EAAM,YAAY,QAAoB,EAAA;AAAA;AAAA;AAAA,KAClD;AAAA;AAGN,CAAC","file":"chunk-6ANKBOX6.cjs","sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Mock, MockWithFaker } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n pluginManager,\n plugin: {\n options: { output, parser, baseURL },\n },\n } = useApp<PluginMsw>()\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith('2'))\n const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200\n\n return (\n <File\n baseName={mock.file.baseName}\n path={mock.file.path}\n meta={mock.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['http']} path=\"msw\" />\n <File.Import name={['ResponseResolver']} isTypeOnly path=\"msw\" />\n <File.Import name={[type.schemas.response.name]} path={type.file.path} root={mock.file.path} isTypeOnly />\n {parser === 'faker' && faker.file && faker.schemas.response && (\n <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />\n )}\n\n {parser === 'faker' && (\n <MockWithFaker\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n baseURL={baseURL}\n url={new URLPath(operation.path).toURLPath().replace(/([^/]):/g, '$1\\\\\\\\:')}\n statusCode={statusCode}\n />\n )}\n {parser === 'data' && (\n <Mock\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n baseURL={baseURL}\n url={new URLPath(operation.path).toURLPath().replace(/([^/]):/g, '$1\\\\\\\\:')}\n statusCode={statusCode}\n />\n )}\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Handlers } from '../components/Handlers.tsx'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations }) {\n const { pluginManager, plugin } = useApp<PluginMsw>()\n const oas = useOas()\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginKey: plugin.key })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: plugin.key })\n const operationName = getName(operation, { pluginKey: plugin.key, type: 'function' })\n\n return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n\n const handlers = operations.map((operation) => `${getName(operation, { type: 'function', pluginKey: plugin.key })}()`)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
@@ -1,55 +0,0 @@
1
- 'use strict';
2
-
3
- var react = require('@kubb/react');
4
- var jsxRuntime = require('@kubb/react/jsx-runtime');
5
-
6
- // src/components/Mock.tsx
7
- function Mock({ baseURL = "", name, typeName, url, method, statusCode }) {
8
- const params = react.FunctionParams.factory({
9
- data: {
10
- type: `${typeName} | ((
11
- info: Parameters<Parameters<typeof http.${method}>[1]>[0],
12
- ) => Response)`,
13
- optional: true
14
- }
15
- });
16
- return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('${baseURL}${url.replace(/([^/]):/g, "$1\\\\:")}', function handler(info) {
17
- if(typeof data === 'function') return data(info)
18
-
19
- return new Response(JSON.stringify(data), {
20
- status: ${statusCode},
21
- headers: {
22
- 'Content-Type': 'application/json',
23
- },
24
- })
25
- })` }) });
26
- }
27
- function Handlers({ name, handlers }) {
28
- return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
29
- }
30
- function MockWithFaker({ baseURL = "", name, fakerName, typeName, url, method, statusCode }) {
31
- const params = react.FunctionParams.factory({
32
- data: {
33
- type: `${typeName} | ((
34
- info: Parameters<Parameters<typeof http.${method}>[1]>[0],
35
- ) => Response)`,
36
- optional: true
37
- }
38
- });
39
- return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('${baseURL}${url.replace(/([^/]):/g, "$1\\\\:")}', function handler(info) {
40
- if(typeof data === 'function') return data(info)
41
-
42
- return new Response(JSON.stringify(data || ${fakerName}(data)), {
43
- status: ${statusCode},
44
- headers: {
45
- 'Content-Type': 'application/json',
46
- },
47
- })
48
- })` }) });
49
- }
50
-
51
- exports.Handlers = Handlers;
52
- exports.Mock = Mock;
53
- exports.MockWithFaker = MockWithFaker;
54
- //# sourceMappingURL=chunk-FYUFQXX6.cjs.map
55
- //# sourceMappingURL=chunk-FYUFQXX6.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx","../src/components/MockWithFaker.tsx"],"names":["FunctionParams","jsx","File","Function"],"mappings":";;;;;;AAkBO,SAAS,IAAA,CAAK,EAAE,OAAU,GAAA,EAAA,EAAI,MAAM,QAAU,EAAA,GAAA,EAAK,MAAQ,EAAA,UAAA,EAAgC,EAAA;AAChG,EAAM,MAAA,MAAA,GAASA,qBAAe,OAAQ,CAAA;AAAA,IACpC,IAAM,EAAA;AAAA,MACJ,IAAA,EAAM,GAAG,QAAQ,CAAA;AAAA,gDAAA,EAC2B,MAAM,CAAA;AAAA,oBAAA,CAAA;AAAA,MAElD,QAAU,EAAA;AAAA;AACZ,GACD,CAAA;AAED,EACE,uBAAAC,cAAA,CAACC,UAAK,CAAA,MAAA,EAAL,EAAY,IAAA,EAAY,WAAW,EAAA,IAAA,EAAC,YAAY,EAAA,IAAA,EAC/C,QAAC,kBAAAD,cAAA,CAAAE,cAAA,EAAA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AAA,EACvD,QAAe,EAAA,CAAA,YAAA,EAAA,MAAM,CAAK,EAAA,EAAA,OAAO,CAAG,EAAA,GAAA,CAAI,OAAQ,CAAA,UAAA,EAAY,SAAS,CAAC,CAAA;AAAA;;AAAA,+CAAA,EAG9B,SAAS,CAAA;AAAA,cAAA,EAC1C,UAAU,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EAMpB,CACF,EAAA,CAAA;AAEJ","file":"chunk-FYUFQXX6.cjs","sourcesContent":["import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n baseURL: string | undefined\n method: HttpMethod\n statusCode: number\n}\n\nexport function Mock({ baseURL = '', name, typeName, url, method, statusCode }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: `${typeName} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response)`,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('${baseURL}${url.replace(/([^/]):/g, '$1\\\\\\\\:')}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data), {\n status: ${statusCode},\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n","import { File } from '@kubb/react'\nimport type { ReactNode } from 'react'\n\ntype HandlersProps = {\n /**\n * Name of the function\n */\n name: string\n // custom\n handlers: string[]\n}\n\nexport function Handlers({ name, handlers }: HandlersProps): ReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}\n </File.Source>\n )\n}\n","import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n baseURL: string | undefined\n url: string\n method: HttpMethod\n statusCode: number\n}\n\nexport function MockWithFaker({ baseURL = '', name, fakerName, typeName, url, method, statusCode }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: `${typeName} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response)`,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('${baseURL}${url.replace(/([^/]):/g, '$1\\\\\\\\:')}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data || ${fakerName}(data)), {\n status: ${statusCode},\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n"]}
@@ -1,110 +0,0 @@
1
- import { MockWithFaker, Mock, Handlers } from './chunk-HL53J5NZ.js';
2
- import { URLPath } from '@kubb/core/utils';
3
- import { pluginFakerName } from '@kubb/plugin-faker';
4
- import { createReactGenerator } from '@kubb/plugin-oas';
5
- import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks';
6
- import { getFooter, getBanner } from '@kubb/plugin-oas/utils';
7
- import { pluginTsName } from '@kubb/plugin-ts';
8
- import { useApp, File } from '@kubb/react';
9
- import { jsxs, jsx } from '@kubb/react/jsx-runtime';
10
-
11
- var mswGenerator = createReactGenerator({
12
- name: "msw",
13
- Operation({ operation }) {
14
- const {
15
- pluginManager,
16
- plugin: {
17
- options: { output, parser, baseURL }
18
- }
19
- } = useApp();
20
- const oas = useOas();
21
- const { getSchemas, getName, getFile } = useOperationManager();
22
- const mock = {
23
- name: getName(operation, { type: "function" }),
24
- file: getFile(operation)
25
- };
26
- const faker = {
27
- file: getFile(operation, { pluginKey: [pluginFakerName] }),
28
- schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: "function" })
29
- };
30
- const type = {
31
- file: getFile(operation, { pluginKey: [pluginTsName] }),
32
- schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
33
- };
34
- const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith("2"));
35
- const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200;
36
- return /* @__PURE__ */ jsxs(
37
- File,
38
- {
39
- baseName: mock.file.baseName,
40
- path: mock.file.path,
41
- meta: mock.file.meta,
42
- banner: getBanner({ oas, output, config: pluginManager.config }),
43
- footer: getFooter({ oas, output }),
44
- children: [
45
- /* @__PURE__ */ jsx(File.Import, { name: ["http"], path: "msw" }),
46
- /* @__PURE__ */ jsx(File.Import, { name: ["ResponseResolver"], isTypeOnly: true, path: "msw" }),
47
- /* @__PURE__ */ jsx(File.Import, { name: [type.schemas.response.name], path: type.file.path, root: mock.file.path, isTypeOnly: true }),
48
- parser === "faker" && faker.file && faker.schemas.response && /* @__PURE__ */ jsx(File.Import, { name: [faker.schemas.response.name], root: mock.file.path, path: faker.file.path }),
49
- parser === "faker" && /* @__PURE__ */ jsx(
50
- MockWithFaker,
51
- {
52
- name: mock.name,
53
- typeName: type.schemas.response.name,
54
- fakerName: faker.schemas.response.name,
55
- method: operation.method,
56
- baseURL,
57
- url: new URLPath(operation.path).toURLPath().replace(/([^/]):/g, "$1\\\\:"),
58
- statusCode
59
- }
60
- ),
61
- parser === "data" && /* @__PURE__ */ jsx(
62
- Mock,
63
- {
64
- name: mock.name,
65
- typeName: type.schemas.response.name,
66
- fakerName: faker.schemas.response.name,
67
- method: operation.method,
68
- baseURL,
69
- url: new URLPath(operation.path).toURLPath().replace(/([^/]):/g, "$1\\\\:"),
70
- statusCode
71
- }
72
- )
73
- ]
74
- }
75
- );
76
- }
77
- });
78
- var handlersGenerator = createReactGenerator({
79
- name: "plugin-msw",
80
- Operations({ operations }) {
81
- const { pluginManager, plugin } = useApp();
82
- const oas = useOas();
83
- const { getName, getFile } = useOperationManager();
84
- const file = pluginManager.getFile({ name: "handlers", extname: ".ts", pluginKey: plugin.key });
85
- const imports = operations.map((operation) => {
86
- const operationFile = getFile(operation, { pluginKey: plugin.key });
87
- const operationName = getName(operation, { pluginKey: plugin.key, type: "function" });
88
- return /* @__PURE__ */ jsx(File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
89
- });
90
- const handlers = operations.map((operation) => `${getName(operation, { type: "function", pluginKey: plugin.key })}()`);
91
- return /* @__PURE__ */ jsxs(
92
- File,
93
- {
94
- baseName: file.baseName,
95
- path: file.path,
96
- meta: file.meta,
97
- banner: getBanner({ oas, output: plugin.options.output, config: pluginManager.config }),
98
- footer: getFooter({ oas, output: plugin.options.output }),
99
- children: [
100
- imports,
101
- /* @__PURE__ */ jsx(Handlers, { name: "handlers", handlers })
102
- ]
103
- }
104
- );
105
- }
106
- });
107
-
108
- export { handlersGenerator, mswGenerator };
109
- //# sourceMappingURL=chunk-GUSADLEP.js.map
110
- //# sourceMappingURL=chunk-GUSADLEP.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/generators/mswGenerator.tsx","../src/generators/handlersGenerator.tsx"],"names":["createReactGenerator","useApp","useOas","useOperationManager","jsx","File","jsxs","getBanner","getFooter"],"mappings":";;;;;;;;;;AAUO,IAAM,eAAe,oBAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,MACJ,aAAA;AAAA,MACA,MAAQ,EAAA;AAAA,QACN,OAAS,EAAA,EAAE,MAAQ,EAAA,MAAA,EAAQ,OAAQ;AAAA;AACrC,QACE,MAAkB,EAAA;AACtB,IAAA,MAAM,MAAM,MAAO,EAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAY,mBAAoB,EAAA;AAE7D,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7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KAAK,IAAM,EAAA,IAAA,EAAM,aAAc,CAAA,IAAA,EAAA,EAAhF,cAAc,IAAwE,CAAA;AAAA,KAChH,CAAA;AAED,IAAA,MAAM,WAAW,UAAW,CAAA,GAAA,CAAI,CAAC,SAAA,KAAc,GAAG,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,SAAW,EAAA,MAAA,CAAO,GAAI,EAAC,CAAC,CAAI,EAAA,CAAA,CAAA;AAErH,IAAA,uBACEC,IAAAA;AAAA,MAACD,IAAAA;AAAA,MAAA;AAAA,QACC,UAAU,IAAK,CAAA,QAAA;AAAA,QACf,MAAM,IAAK,CAAA,IAAA;AAAA,QACX,MAAM,IAAK,CAAA,IAAA;AAAA,QACX,MAAA,EAAQE,SAAU,CAAA,EAAE,GAAK,EAAA,MAAA,EAAQ,MAAO,CAAA,OAAA,CAAQ,MAAQ,EAAA,MAAA,EAAQ,aAAc,CAAA,MAAA,EAAQ,CAAA;AAAA,QACtF,MAAA,EAAQC,UAAU,EAAE,GAAA,EAAK,QAAQ,MAAO,CAAA,OAAA,CAAQ,QAAQ,CAAA;AAAA,QAEvD,QAAA,EAAA;AAAA,UAAA,OAAA;AAAA,0BACDJ,GAAAA,CAAC,QAAS,EAAA,EAAA,IAAA,EAAM,YAAY,QAAoB,EAAA;AAAA;AAAA;AAAA,KAClD;AAAA;AAGN,CAAC","file":"chunk-GUSADLEP.js","sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Mock, MockWithFaker } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n pluginManager,\n plugin: {\n options: { output, parser, baseURL },\n },\n } = useApp<PluginMsw>()\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith('2'))\n const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200\n\n return (\n <File\n baseName={mock.file.baseName}\n path={mock.file.path}\n meta={mock.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['http']} path=\"msw\" />\n <File.Import name={['ResponseResolver']} isTypeOnly path=\"msw\" />\n <File.Import name={[type.schemas.response.name]} path={type.file.path} root={mock.file.path} isTypeOnly />\n {parser === 'faker' && faker.file && faker.schemas.response && (\n <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />\n )}\n\n {parser === 'faker' && (\n <MockWithFaker\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n baseURL={baseURL}\n url={new URLPath(operation.path).toURLPath().replace(/([^/]):/g, '$1\\\\\\\\:')}\n statusCode={statusCode}\n />\n )}\n {parser === 'data' && (\n <Mock\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n baseURL={baseURL}\n url={new URLPath(operation.path).toURLPath().replace(/([^/]):/g, '$1\\\\\\\\:')}\n statusCode={statusCode}\n />\n )}\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Handlers } from '../components/Handlers.tsx'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations }) {\n const { pluginManager, plugin } = useApp<PluginMsw>()\n const oas = useOas()\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginKey: plugin.key })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: plugin.key })\n const operationName = getName(operation, { pluginKey: plugin.key, type: 'function' })\n\n return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n\n const handlers = operations.map((operation) => `${getName(operation, { type: 'function', pluginKey: plugin.key })}()`)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}