@kubb/plugin-msw 3.0.0-alpha.2 → 3.0.0-alpha.21
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.
- package/README.md +13 -4
- package/dist/chunk-6M2QU6UL.js +22 -0
- package/dist/chunk-6M2QU6UL.js.map +1 -0
- package/dist/chunk-73P6BBZZ.js +125 -0
- package/dist/chunk-73P6BBZZ.js.map +1 -0
- package/dist/chunk-GODA4G5K.cjs +25 -0
- package/dist/chunk-GODA4G5K.cjs.map +1 -0
- package/dist/chunk-UZ4ZUY3N.cjs +134 -0
- package/dist/chunk-UZ4ZUY3N.cjs.map +1 -0
- package/dist/components.cjs +11 -4
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +7 -70
- package/dist/components.d.ts +7 -70
- package/dist/components.js +2 -8
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +17 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +9 -0
- package/dist/generators.d.ts +9 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +11 -137
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -86
- package/dist/index.d.ts +3 -86
- package/dist/index.js +3 -142
- package/dist/index.js.map +1 -1
- package/dist/types-B2IuaP_7.d.cts +60 -0
- package/dist/types-B2IuaP_7.d.ts +60 -0
- package/package.json +22 -17
- package/src/components/Handlers.tsx +19 -0
- package/src/components/Mock.tsx +9 -92
- package/src/components/index.ts +1 -1
- package/src/generators/__snapshots__/createPet.ts +9 -0
- package/src/generators/__snapshots__/deletePet.ts +9 -0
- package/src/generators/__snapshots__/getPets.ts +9 -0
- package/src/generators/__snapshots__/handlers.ts +3 -0
- package/src/generators/__snapshots__/showPetById.ts +9 -0
- package/src/generators/handlersGenerator.tsx +32 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/mswGenerator.tsx +38 -0
- package/src/plugin.ts +16 -34
- package/src/types.ts +9 -38
- package/dist/chunk-S4P5XPFN.cjs +0 -105
- package/dist/chunk-S4P5XPFN.cjs.map +0 -1
- package/dist/chunk-WRIEMCYI.js +0 -105
- package/dist/chunk-WRIEMCYI.js.map +0 -1
- package/src/OperationGenerator.tsx +0 -66
- package/src/components/Operations.tsx +0 -96
- package/src/components/__snapshots__/Mock/Pets.ts +0 -7
- package/src/components/__snapshots__/Mock/showPetsById.ts +0 -7
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkUZ4ZUY3N_cjs = require('./chunk-UZ4ZUY3N.cjs');
|
|
4
|
+
require('./chunk-GODA4G5K.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, "handlersGenerator", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunkUZ4ZUY3N_cjs.handlersGenerator; }
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "mswGenerator", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return chunkUZ4ZUY3N_cjs.mswGenerator; }
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=generators.cjs.map
|
|
17
|
+
//# sourceMappingURL=generators.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"generators.cjs"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as _kubb_plugin_oas from '@kubb/plugin-oas';
|
|
2
|
+
import { P as PluginMsw } from './types-B2IuaP_7.cjs';
|
|
3
|
+
import '@kubb/core';
|
|
4
|
+
|
|
5
|
+
declare const mswGenerator: _kubb_plugin_oas.Generator<PluginMsw>;
|
|
6
|
+
|
|
7
|
+
declare const handlersGenerator: _kubb_plugin_oas.Generator<PluginMsw>;
|
|
8
|
+
|
|
9
|
+
export { handlersGenerator, mswGenerator };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as _kubb_plugin_oas from '@kubb/plugin-oas';
|
|
2
|
+
import { P as PluginMsw } from './types-B2IuaP_7.js';
|
|
3
|
+
import '@kubb/core';
|
|
4
|
+
|
|
5
|
+
declare const mswGenerator: _kubb_plugin_oas.Generator<PluginMsw>;
|
|
6
|
+
|
|
7
|
+
declare const handlersGenerator: _kubb_plugin_oas.Generator<PluginMsw>;
|
|
8
|
+
|
|
9
|
+
export { handlersGenerator, mswGenerator };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"generators.js"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,143 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunkUZ4ZUY3N_cjs = require('./chunk-UZ4ZUY3N.cjs');
|
|
4
|
+
require('./chunk-GODA4G5K.cjs');
|
|
3
5
|
|
|
4
|
-
var _chunkS4P5XPFNcjs = require('./chunk-S4P5XPFN.cjs');
|
|
5
6
|
|
|
6
|
-
// src/plugin.ts
|
|
7
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
8
|
-
var _core = require('@kubb/core');
|
|
9
|
-
var _transformers = require('@kubb/core/transformers');
|
|
10
|
-
var _utils = require('@kubb/core/utils');
|
|
11
|
-
var _pluginoas = require('@kubb/plugin-oas');
|
|
12
|
-
var _utils3 = require('@kubb/plugin-oas/utils');
|
|
13
|
-
var _pluginfaker = require('@kubb/plugin-faker');
|
|
14
|
-
var _plugints = require('@kubb/plugin-ts');
|
|
15
7
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var _react = require('@kubb/react');
|
|
20
|
-
var _jsxruntime = require('@kubb/react/jsx-runtime');
|
|
21
|
-
var OperationGenerator = class extends _pluginoas.OperationGenerator {
|
|
22
|
-
async all(operations, operationsByMethod) {
|
|
23
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
|
24
|
-
const root = _react.createRoot.call(void 0, {
|
|
25
|
-
logger: pluginManager.logger
|
|
26
|
-
});
|
|
27
|
-
const templates = {
|
|
28
|
-
operations: _chunkS4P5XPFNcjs.Operations.templates,
|
|
29
|
-
mock: _chunkS4P5XPFNcjs.Mock.templates,
|
|
30
|
-
...this.options.templates
|
|
31
|
-
};
|
|
32
|
-
root.render(
|
|
33
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations, generator: this, children: _optionalChain([templates, 'optionalAccess', _ => _.operations]) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkS4P5XPFNcjs.Operations.File, { templates: templates.operations }) }) })
|
|
34
|
-
);
|
|
35
|
-
return root.files;
|
|
36
|
-
}
|
|
37
|
-
async operation(operation, options) {
|
|
38
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
|
39
|
-
const root = _react.createRoot.call(void 0, {
|
|
40
|
-
logger: pluginManager.logger
|
|
41
|
-
});
|
|
42
|
-
const templates = {
|
|
43
|
-
handlers: _chunkS4P5XPFNcjs.Operations.templates,
|
|
44
|
-
mock: _chunkS4P5XPFNcjs.Mock.templates,
|
|
45
|
-
...options.templates
|
|
46
|
-
};
|
|
47
|
-
if (!_optionalChain([templates, 'optionalAccess', _2 => _2.mock])) {
|
|
48
|
-
return [];
|
|
49
|
-
}
|
|
50
|
-
root.render(
|
|
51
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Operation, { operation, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkS4P5XPFNcjs.Mock.File, { templates: templates.mock }) }) }) })
|
|
52
|
-
);
|
|
53
|
-
return root.files;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
// src/plugin.ts
|
|
58
|
-
var pluginMswName = "plugin-msw";
|
|
59
|
-
var pluginMsw = _core.createPlugin.call(void 0, (options) => {
|
|
60
|
-
const { output = { path: "handlers" }, group, exclude = [], include, override = [], transformers = {}, templates } = options;
|
|
61
|
-
const template = _optionalChain([group, 'optionalAccess', _3 => _3.output]) ? group.output : `${output.path}/{{tag}}Controller`;
|
|
62
|
-
return {
|
|
63
|
-
name: pluginMswName,
|
|
64
|
-
options: {
|
|
65
|
-
extName: output.extName,
|
|
66
|
-
templates: {
|
|
67
|
-
operations: _chunkS4P5XPFNcjs.Operations.templates,
|
|
68
|
-
mock: _chunkS4P5XPFNcjs.Mock.templates,
|
|
69
|
-
...templates
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
pre: [_pluginoas.pluginOasName, _plugints.pluginTsName, _pluginfaker.pluginFakerName],
|
|
73
|
-
resolvePath(baseName, pathMode, options2) {
|
|
74
|
-
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
75
|
-
const mode = _nullishCoalesce(pathMode, () => ( _core.FileManager.getMode(_path2.default.resolve(root, output.path))));
|
|
76
|
-
if (mode === "single") {
|
|
77
|
-
return _path2.default.resolve(root, output.path);
|
|
78
|
-
}
|
|
79
|
-
if (_optionalChain([options2, 'optionalAccess', _4 => _4.tag]) && _optionalChain([group, 'optionalAccess', _5 => _5.type]) === "tag") {
|
|
80
|
-
const tag = _transformers.camelCase.call(void 0, options2.tag);
|
|
81
|
-
return _path2.default.resolve(root, _utils.renderTemplate.call(void 0, template, { tag }), baseName);
|
|
82
|
-
}
|
|
83
|
-
return _path2.default.resolve(root, output.path, baseName);
|
|
84
|
-
},
|
|
85
|
-
resolveName(name, type) {
|
|
86
|
-
const resolvedName = _transformers.camelCase.call(void 0, name, {
|
|
87
|
-
suffix: type ? "handler" : void 0,
|
|
88
|
-
isFile: type === "file"
|
|
89
|
-
});
|
|
90
|
-
if (type) {
|
|
91
|
-
return _optionalChain([transformers, 'optionalAccess', _6 => _6.name, 'optionalCall', _7 => _7(resolvedName, type)]) || resolvedName;
|
|
92
|
-
}
|
|
93
|
-
return resolvedName;
|
|
94
|
-
},
|
|
95
|
-
async buildStart() {
|
|
96
|
-
const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
|
|
97
|
-
const oas = await swaggerPlugin.context.getOas();
|
|
98
|
-
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
99
|
-
const mode = _core.FileManager.getMode(_path2.default.resolve(root, output.path));
|
|
100
|
-
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
101
|
-
oas,
|
|
102
|
-
pluginManager: this.pluginManager,
|
|
103
|
-
plugin: this.plugin,
|
|
104
|
-
contentType: swaggerPlugin.context.contentType,
|
|
105
|
-
exclude,
|
|
106
|
-
include,
|
|
107
|
-
override,
|
|
108
|
-
mode
|
|
109
|
-
});
|
|
110
|
-
const files = await operationGenerator.build();
|
|
111
|
-
await this.addFile(...files);
|
|
112
|
-
},
|
|
113
|
-
async buildEnd() {
|
|
114
|
-
if (this.config.output.write === false) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
118
|
-
if (_optionalChain([group, 'optionalAccess', _8 => _8.type]) === "tag") {
|
|
119
|
-
const rootFiles = await _utils3.getGroupedByTagFiles.call(void 0, {
|
|
120
|
-
logger: this.logger,
|
|
121
|
-
files: this.fileManager.files,
|
|
122
|
-
plugin: this.plugin,
|
|
123
|
-
template,
|
|
124
|
-
exportAs: group.exportAs || "{{tag}}Handlers",
|
|
125
|
-
root,
|
|
126
|
-
output
|
|
127
|
-
});
|
|
128
|
-
await this.addFile(...rootFiles);
|
|
129
|
-
}
|
|
130
|
-
await this.fileManager.addIndexes({
|
|
131
|
-
root,
|
|
132
|
-
output,
|
|
133
|
-
meta: { pluginKey: this.plugin.key },
|
|
134
|
-
logger: this.logger
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
};
|
|
8
|
+
Object.defineProperty(exports, "pluginMsw", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunkUZ4ZUY3N_cjs.pluginMsw; }
|
|
138
11
|
});
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
12
|
+
Object.defineProperty(exports, "pluginMswName", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return chunkUZ4ZUY3N_cjs.pluginMswName; }
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=index.cjs.map
|
|
143
17
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,91 +1,8 @@
|
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
|
|
5
|
-
import { Operations, Mock } from './components.cjs';
|
|
6
|
-
import '@kubb/core/utils';
|
|
7
|
-
import '@kubb/oas';
|
|
8
|
-
import 'react';
|
|
9
|
-
import '@kubb/react';
|
|
10
|
-
|
|
11
|
-
type Templates = {
|
|
12
|
-
operations?: typeof Operations.templates | false;
|
|
13
|
-
mock?: typeof Mock.templates | false;
|
|
14
|
-
};
|
|
15
|
-
type Options = {
|
|
16
|
-
output?: {
|
|
17
|
-
/**
|
|
18
|
-
* Relative path to save the MSW mocks.
|
|
19
|
-
* When output is a file it will save all models inside that file else it will create a file per schema item.
|
|
20
|
-
* @default 'mocks'
|
|
21
|
-
*/
|
|
22
|
-
path: string;
|
|
23
|
-
/**
|
|
24
|
-
* Name to be used for the `export * as {{exportAs}} from './'`
|
|
25
|
-
*/
|
|
26
|
-
exportAs?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Add an extension to the generated imports and exports, default it will not use an extension
|
|
29
|
-
*/
|
|
30
|
-
extName?: KubbFile.Extname;
|
|
31
|
-
/**
|
|
32
|
-
* Define what needs to exported, here you can also disable the export of barrel files
|
|
33
|
-
* @default `'barrel'`
|
|
34
|
-
*/
|
|
35
|
-
exportType?: 'barrel' | 'barrelNamed' | false;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Group the MSW mocks based on the provided name.
|
|
39
|
-
*/
|
|
40
|
-
group?: {
|
|
41
|
-
/**
|
|
42
|
-
* Tag will group based on the operation tag inside the Swagger file
|
|
43
|
-
*/
|
|
44
|
-
type: 'tag';
|
|
45
|
-
/**
|
|
46
|
-
* Relative path to save the grouped MSW mocks.
|
|
47
|
-
*
|
|
48
|
-
* `{{tag}}` will be replaced by the current tagName.
|
|
49
|
-
* @example `${output}/{{tag}}Controller` => `mocks/PetController`
|
|
50
|
-
* @default `${output}/{{tag}}Controller`
|
|
51
|
-
*/
|
|
52
|
-
output?: string;
|
|
53
|
-
/**
|
|
54
|
-
* Name to be used for the `export * as {{exportAs}} from './`
|
|
55
|
-
* @default `"{{tag}}Handlers"`
|
|
56
|
-
*/
|
|
57
|
-
exportAs?: string;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
61
|
-
*/
|
|
62
|
-
exclude?: Array<Exclude>;
|
|
63
|
-
/**
|
|
64
|
-
* Array containing include parameters to include tags/operations/methods/paths.
|
|
65
|
-
*/
|
|
66
|
-
include?: Array<Include>;
|
|
67
|
-
/**
|
|
68
|
-
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
69
|
-
*/
|
|
70
|
-
override?: Array<Override<ResolvedOptions>>;
|
|
71
|
-
transformers?: {
|
|
72
|
-
/**
|
|
73
|
-
* Customize the names based on the type that is provided by the plugin.
|
|
74
|
-
*/
|
|
75
|
-
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* Make it possible to override one of the templates
|
|
79
|
-
*/
|
|
80
|
-
templates?: Partial<Templates>;
|
|
81
|
-
};
|
|
82
|
-
type ResolvedOptions = {
|
|
83
|
-
extName: KubbFile.Extname | undefined;
|
|
84
|
-
templates: NonNullable<Templates>;
|
|
85
|
-
};
|
|
86
|
-
type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
2
|
+
import { O as Options, P as PluginMsw } from './types-B2IuaP_7.cjs';
|
|
3
|
+
import '@kubb/plugin-oas';
|
|
87
4
|
|
|
88
5
|
declare const pluginMswName = "plugin-msw";
|
|
89
6
|
declare const pluginMsw: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginMsw>;
|
|
90
7
|
|
|
91
|
-
export {
|
|
8
|
+
export { PluginMsw, pluginMsw, pluginMswName };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,91 +1,8 @@
|
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
|
|
5
|
-
import { Operations, Mock } from './components.js';
|
|
6
|
-
import '@kubb/core/utils';
|
|
7
|
-
import '@kubb/oas';
|
|
8
|
-
import 'react';
|
|
9
|
-
import '@kubb/react';
|
|
10
|
-
|
|
11
|
-
type Templates = {
|
|
12
|
-
operations?: typeof Operations.templates | false;
|
|
13
|
-
mock?: typeof Mock.templates | false;
|
|
14
|
-
};
|
|
15
|
-
type Options = {
|
|
16
|
-
output?: {
|
|
17
|
-
/**
|
|
18
|
-
* Relative path to save the MSW mocks.
|
|
19
|
-
* When output is a file it will save all models inside that file else it will create a file per schema item.
|
|
20
|
-
* @default 'mocks'
|
|
21
|
-
*/
|
|
22
|
-
path: string;
|
|
23
|
-
/**
|
|
24
|
-
* Name to be used for the `export * as {{exportAs}} from './'`
|
|
25
|
-
*/
|
|
26
|
-
exportAs?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Add an extension to the generated imports and exports, default it will not use an extension
|
|
29
|
-
*/
|
|
30
|
-
extName?: KubbFile.Extname;
|
|
31
|
-
/**
|
|
32
|
-
* Define what needs to exported, here you can also disable the export of barrel files
|
|
33
|
-
* @default `'barrel'`
|
|
34
|
-
*/
|
|
35
|
-
exportType?: 'barrel' | 'barrelNamed' | false;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Group the MSW mocks based on the provided name.
|
|
39
|
-
*/
|
|
40
|
-
group?: {
|
|
41
|
-
/**
|
|
42
|
-
* Tag will group based on the operation tag inside the Swagger file
|
|
43
|
-
*/
|
|
44
|
-
type: 'tag';
|
|
45
|
-
/**
|
|
46
|
-
* Relative path to save the grouped MSW mocks.
|
|
47
|
-
*
|
|
48
|
-
* `{{tag}}` will be replaced by the current tagName.
|
|
49
|
-
* @example `${output}/{{tag}}Controller` => `mocks/PetController`
|
|
50
|
-
* @default `${output}/{{tag}}Controller`
|
|
51
|
-
*/
|
|
52
|
-
output?: string;
|
|
53
|
-
/**
|
|
54
|
-
* Name to be used for the `export * as {{exportAs}} from './`
|
|
55
|
-
* @default `"{{tag}}Handlers"`
|
|
56
|
-
*/
|
|
57
|
-
exportAs?: string;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
61
|
-
*/
|
|
62
|
-
exclude?: Array<Exclude>;
|
|
63
|
-
/**
|
|
64
|
-
* Array containing include parameters to include tags/operations/methods/paths.
|
|
65
|
-
*/
|
|
66
|
-
include?: Array<Include>;
|
|
67
|
-
/**
|
|
68
|
-
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
69
|
-
*/
|
|
70
|
-
override?: Array<Override<ResolvedOptions>>;
|
|
71
|
-
transformers?: {
|
|
72
|
-
/**
|
|
73
|
-
* Customize the names based on the type that is provided by the plugin.
|
|
74
|
-
*/
|
|
75
|
-
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* Make it possible to override one of the templates
|
|
79
|
-
*/
|
|
80
|
-
templates?: Partial<Templates>;
|
|
81
|
-
};
|
|
82
|
-
type ResolvedOptions = {
|
|
83
|
-
extName: KubbFile.Extname | undefined;
|
|
84
|
-
templates: NonNullable<Templates>;
|
|
85
|
-
};
|
|
86
|
-
type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
2
|
+
import { O as Options, P as PluginMsw } from './types-B2IuaP_7.js';
|
|
3
|
+
import '@kubb/plugin-oas';
|
|
87
4
|
|
|
88
5
|
declare const pluginMswName = "plugin-msw";
|
|
89
6
|
declare const pluginMsw: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginMsw>;
|
|
90
7
|
|
|
91
|
-
export {
|
|
8
|
+
export { PluginMsw, pluginMsw, pluginMswName };
|
package/dist/index.js
CHANGED
|
@@ -1,143 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./chunk-WRIEMCYI.js";
|
|
5
|
-
|
|
6
|
-
// src/plugin.ts
|
|
7
|
-
import path from "path";
|
|
8
|
-
import { FileManager, PluginManager, createPlugin } from "@kubb/core";
|
|
9
|
-
import { camelCase } from "@kubb/core/transformers";
|
|
10
|
-
import { renderTemplate } from "@kubb/core/utils";
|
|
11
|
-
import { pluginOasName } from "@kubb/plugin-oas";
|
|
12
|
-
import { getGroupedByTagFiles } from "@kubb/plugin-oas/utils";
|
|
13
|
-
import { pluginFakerName } from "@kubb/plugin-faker";
|
|
14
|
-
import { pluginTsName } from "@kubb/plugin-ts";
|
|
15
|
-
|
|
16
|
-
// src/OperationGenerator.tsx
|
|
17
|
-
import { OperationGenerator as Generator } from "@kubb/plugin-oas";
|
|
18
|
-
import { Oas } from "@kubb/plugin-oas/components";
|
|
19
|
-
import { App, createRoot } from "@kubb/react";
|
|
20
|
-
import { jsx } from "@kubb/react/jsx-runtime";
|
|
21
|
-
var OperationGenerator = class extends Generator {
|
|
22
|
-
async all(operations, operationsByMethod) {
|
|
23
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
|
24
|
-
const root = createRoot({
|
|
25
|
-
logger: pluginManager.logger
|
|
26
|
-
});
|
|
27
|
-
const templates = {
|
|
28
|
-
operations: Operations.templates,
|
|
29
|
-
mock: Mock.templates,
|
|
30
|
-
...this.options.templates
|
|
31
|
-
};
|
|
32
|
-
root.render(
|
|
33
|
-
/* @__PURE__ */ jsx(App, { pluginManager, plugin, mode, children: /* @__PURE__ */ jsx(Oas, { oas, operations, generator: this, children: templates?.operations && /* @__PURE__ */ jsx(Operations.File, { templates: templates.operations }) }) })
|
|
34
|
-
);
|
|
35
|
-
return root.files;
|
|
36
|
-
}
|
|
37
|
-
async operation(operation, options) {
|
|
38
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
|
39
|
-
const root = createRoot({
|
|
40
|
-
logger: pluginManager.logger
|
|
41
|
-
});
|
|
42
|
-
const templates = {
|
|
43
|
-
handlers: Operations.templates,
|
|
44
|
-
mock: Mock.templates,
|
|
45
|
-
...options.templates
|
|
46
|
-
};
|
|
47
|
-
if (!templates?.mock) {
|
|
48
|
-
return [];
|
|
49
|
-
}
|
|
50
|
-
root.render(
|
|
51
|
-
/* @__PURE__ */ jsx(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx(Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsx(Oas.Operation, { operation, children: /* @__PURE__ */ jsx(Mock.File, { templates: templates.mock }) }) }) })
|
|
52
|
-
);
|
|
53
|
-
return root.files;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
// src/plugin.ts
|
|
58
|
-
var pluginMswName = "plugin-msw";
|
|
59
|
-
var pluginMsw = createPlugin((options) => {
|
|
60
|
-
const { output = { path: "handlers" }, group, exclude = [], include, override = [], transformers = {}, templates } = options;
|
|
61
|
-
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
62
|
-
return {
|
|
63
|
-
name: pluginMswName,
|
|
64
|
-
options: {
|
|
65
|
-
extName: output.extName,
|
|
66
|
-
templates: {
|
|
67
|
-
operations: Operations.templates,
|
|
68
|
-
mock: Mock.templates,
|
|
69
|
-
...templates
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
pre: [pluginOasName, pluginTsName, pluginFakerName],
|
|
73
|
-
resolvePath(baseName, pathMode, options2) {
|
|
74
|
-
const root = path.resolve(this.config.root, this.config.output.path);
|
|
75
|
-
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
76
|
-
if (mode === "single") {
|
|
77
|
-
return path.resolve(root, output.path);
|
|
78
|
-
}
|
|
79
|
-
if (options2?.tag && group?.type === "tag") {
|
|
80
|
-
const tag = camelCase(options2.tag);
|
|
81
|
-
return path.resolve(root, renderTemplate(template, { tag }), baseName);
|
|
82
|
-
}
|
|
83
|
-
return path.resolve(root, output.path, baseName);
|
|
84
|
-
},
|
|
85
|
-
resolveName(name, type) {
|
|
86
|
-
const resolvedName = camelCase(name, {
|
|
87
|
-
suffix: type ? "handler" : void 0,
|
|
88
|
-
isFile: type === "file"
|
|
89
|
-
});
|
|
90
|
-
if (type) {
|
|
91
|
-
return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
92
|
-
}
|
|
93
|
-
return resolvedName;
|
|
94
|
-
},
|
|
95
|
-
async buildStart() {
|
|
96
|
-
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
97
|
-
const oas = await swaggerPlugin.context.getOas();
|
|
98
|
-
const root = path.resolve(this.config.root, this.config.output.path);
|
|
99
|
-
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
100
|
-
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
101
|
-
oas,
|
|
102
|
-
pluginManager: this.pluginManager,
|
|
103
|
-
plugin: this.plugin,
|
|
104
|
-
contentType: swaggerPlugin.context.contentType,
|
|
105
|
-
exclude,
|
|
106
|
-
include,
|
|
107
|
-
override,
|
|
108
|
-
mode
|
|
109
|
-
});
|
|
110
|
-
const files = await operationGenerator.build();
|
|
111
|
-
await this.addFile(...files);
|
|
112
|
-
},
|
|
113
|
-
async buildEnd() {
|
|
114
|
-
if (this.config.output.write === false) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
const root = path.resolve(this.config.root, this.config.output.path);
|
|
118
|
-
if (group?.type === "tag") {
|
|
119
|
-
const rootFiles = await getGroupedByTagFiles({
|
|
120
|
-
logger: this.logger,
|
|
121
|
-
files: this.fileManager.files,
|
|
122
|
-
plugin: this.plugin,
|
|
123
|
-
template,
|
|
124
|
-
exportAs: group.exportAs || "{{tag}}Handlers",
|
|
125
|
-
root,
|
|
126
|
-
output
|
|
127
|
-
});
|
|
128
|
-
await this.addFile(...rootFiles);
|
|
129
|
-
}
|
|
130
|
-
await this.fileManager.addIndexes({
|
|
131
|
-
root,
|
|
132
|
-
output,
|
|
133
|
-
meta: { pluginKey: this.plugin.key },
|
|
134
|
-
logger: this.logger
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
});
|
|
139
|
-
export {
|
|
140
|
-
pluginMsw,
|
|
141
|
-
pluginMswName
|
|
142
|
-
};
|
|
1
|
+
export { pluginMsw, pluginMswName } from './chunk-73P6BBZZ.js';
|
|
2
|
+
import './chunk-6M2QU6UL.js';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
143
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { PluginFactoryOptions, Output, ResolveNameParams } from '@kubb/core';
|
|
2
|
+
import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
|
|
3
|
+
|
|
4
|
+
type Options = {
|
|
5
|
+
/**
|
|
6
|
+
* @default 'mocks'
|
|
7
|
+
*/
|
|
8
|
+
output?: Output;
|
|
9
|
+
/**
|
|
10
|
+
* Group the MSW mocks based on the provided name.
|
|
11
|
+
*/
|
|
12
|
+
group?: {
|
|
13
|
+
/**
|
|
14
|
+
* Tag will group based on the operation tag inside the Swagger file
|
|
15
|
+
*/
|
|
16
|
+
type: 'tag';
|
|
17
|
+
/**
|
|
18
|
+
* Relative path to save the grouped MSW mocks.
|
|
19
|
+
*
|
|
20
|
+
* `{{tag}}` will be replaced by the current tagName.
|
|
21
|
+
* @example `${output}/{{tag}}Controller` => `mocks/PetController`
|
|
22
|
+
* @default `${output}/{{tag}}Controller`
|
|
23
|
+
*/
|
|
24
|
+
output?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Name to be used for the `export * as {{exportAs}} from './`
|
|
27
|
+
* @default `"{{tag}}Handlers"`
|
|
28
|
+
*/
|
|
29
|
+
exportAs?: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
33
|
+
*/
|
|
34
|
+
exclude?: Array<Exclude>;
|
|
35
|
+
/**
|
|
36
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
37
|
+
*/
|
|
38
|
+
include?: Array<Include>;
|
|
39
|
+
/**
|
|
40
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
41
|
+
*/
|
|
42
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
43
|
+
transformers?: {
|
|
44
|
+
/**
|
|
45
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
46
|
+
*/
|
|
47
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Create `handlers.ts` file with all handlers for all mocks.
|
|
51
|
+
* @default `false`
|
|
52
|
+
*/
|
|
53
|
+
handlers?: boolean;
|
|
54
|
+
};
|
|
55
|
+
type ResolvedOptions = {
|
|
56
|
+
output: Output;
|
|
57
|
+
};
|
|
58
|
+
type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
59
|
+
|
|
60
|
+
export type { Options as O, PluginMsw as P };
|