@kubb/plugin-faker 3.0.0-alpha.0
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/LICENSE +21 -0
- package/README.md +44 -0
- package/dist/components.cjs +577 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +23 -0
- package/dist/components.d.ts +23 -0
- package/dist/components.js +577 -0
- package/dist/components.js.map +1 -0
- package/dist/index.cjs +579 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +135 -0
- package/dist/index.d.ts +135 -0
- package/dist/index.js +579 -0
- package/dist/index.js.map +1 -0
- package/package.json +94 -0
- package/src/OperationGenerator.tsx +30 -0
- package/src/SchemaGenerator.tsx +31 -0
- package/src/components/OperationSchema.tsx +84 -0
- package/src/components/Schema.tsx +146 -0
- package/src/components/index.ts +2 -0
- package/src/index.ts +2 -0
- package/src/parser/index.ts +313 -0
- package/src/plugin.ts +153 -0
- package/src/types.ts +136 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import * as _kubb_core from '@kubb/core';
|
|
2
|
+
import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
|
|
3
|
+
import * as KubbFile from '@kubb/fs/types';
|
|
4
|
+
import { SchemaObject } from '@kubb/oas';
|
|
5
|
+
import { ResolvePathOptions, Exclude, Include, Override, Schema } from '@kubb/plugin-oas';
|
|
6
|
+
|
|
7
|
+
type Options = {
|
|
8
|
+
output?: {
|
|
9
|
+
/**
|
|
10
|
+
* Relative path to save the Faker mocks.
|
|
11
|
+
* When output is a file it will save all models inside that file else it will create a file per schema item.
|
|
12
|
+
* @default 'mocks'
|
|
13
|
+
*/
|
|
14
|
+
path: string;
|
|
15
|
+
/**
|
|
16
|
+
* Name to be used for the `export * as {{exportAs}} from './'`
|
|
17
|
+
*/
|
|
18
|
+
exportAs?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Add an extension to the generated imports and exports, default it will not use an extension
|
|
21
|
+
*/
|
|
22
|
+
extName?: KubbFile.Extname;
|
|
23
|
+
/**
|
|
24
|
+
* Define what needs to exported, here you can also disable the export of barrel files
|
|
25
|
+
* @default `'barrel'`
|
|
26
|
+
*/
|
|
27
|
+
exportType?: 'barrel' | 'barrelNamed' | false;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Group the Faker mocks based on the provided name.
|
|
31
|
+
*/
|
|
32
|
+
group?: {
|
|
33
|
+
/**
|
|
34
|
+
* Tag will group based on the operation tag inside the Swagger file
|
|
35
|
+
*/
|
|
36
|
+
type: 'tag';
|
|
37
|
+
/**
|
|
38
|
+
* Relative path to save the grouped Faker mocks.
|
|
39
|
+
*
|
|
40
|
+
* `{{tag}}` will be replaced by the current tagName.
|
|
41
|
+
* @example `${output}/{{tag}}Controller` => `mocks/PetController`
|
|
42
|
+
* @default `${output}/{{tag}}Controller`
|
|
43
|
+
*/
|
|
44
|
+
output?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Name to be used for the `export * as {{exportAs}} from './`
|
|
47
|
+
* @default `"{{tag}}Mocks"`
|
|
48
|
+
*/
|
|
49
|
+
exportAs?: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
53
|
+
*/
|
|
54
|
+
exclude?: Array<Exclude>;
|
|
55
|
+
/**
|
|
56
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
57
|
+
*/
|
|
58
|
+
include?: Array<Include>;
|
|
59
|
+
/**
|
|
60
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
61
|
+
*/
|
|
62
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
63
|
+
/**
|
|
64
|
+
* Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
|
|
65
|
+
* @default 'string'
|
|
66
|
+
*/
|
|
67
|
+
dateType?: 'string' | 'date';
|
|
68
|
+
/**
|
|
69
|
+
* Which parser should be used when dateType is set to 'string'.
|
|
70
|
+
* - Schema with format 'date' will use ISO date format (YYYY-MM-DD)
|
|
71
|
+
* - `'dayjs'` will use `dayjs(faker.date.anytime()).format("YYYY-MM-DD")`.
|
|
72
|
+
* - `undefined` will use `faker.date.anytime().toString()`
|
|
73
|
+
* - Schema with format 'time' will use ISO time format (HH:mm:ss[.SSSSSS])
|
|
74
|
+
* - `'dayjs'` will use `dayjs(faker.date.anytime()).format("HH:mm:ss")`.
|
|
75
|
+
* - `undefined` will use `faker.date.anytime().toString()`
|
|
76
|
+
* * @default undefined
|
|
77
|
+
*/
|
|
78
|
+
dateParser?: 'dayjs' | 'moment' | (string & {});
|
|
79
|
+
/**
|
|
80
|
+
* Which type to use when the Swagger/OpenAPI file is not providing more information
|
|
81
|
+
* @default 'any'
|
|
82
|
+
*/
|
|
83
|
+
unknownType?: 'any' | 'unknown';
|
|
84
|
+
transformers?: {
|
|
85
|
+
/**
|
|
86
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
87
|
+
*/
|
|
88
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
89
|
+
/**
|
|
90
|
+
* Receive schema and baseName(propertName) and return FakerMeta array
|
|
91
|
+
* TODO TODO add docs
|
|
92
|
+
* @beta
|
|
93
|
+
*/
|
|
94
|
+
schema?: (props: {
|
|
95
|
+
schema?: SchemaObject;
|
|
96
|
+
name?: string;
|
|
97
|
+
parentName?: string;
|
|
98
|
+
}, defaultSchemas: Schema[]) => Schema[] | undefined;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Choose which generator to use when using Regexp.
|
|
102
|
+
*
|
|
103
|
+
* `'faker'` will use `faker.helpers.fromRegExp(new RegExp(/test/))`
|
|
104
|
+
* `'randexp'` will use `new RandExp(/test/).gen()`
|
|
105
|
+
* @default 'faker'
|
|
106
|
+
*/
|
|
107
|
+
regexGenerator?: 'faker' | 'randexp';
|
|
108
|
+
mapper?: Record<string, string>;
|
|
109
|
+
/**
|
|
110
|
+
* The use of Seed is intended to allow for consistent values in a test.
|
|
111
|
+
*/
|
|
112
|
+
seed?: number | number[];
|
|
113
|
+
};
|
|
114
|
+
type ResolvedOptions = {
|
|
115
|
+
extName: KubbFile.Extname | undefined;
|
|
116
|
+
dateType: NonNullable<Options['dateType']>;
|
|
117
|
+
dateParser: Options['dateParser'];
|
|
118
|
+
unknownType: NonNullable<Options['unknownType']>;
|
|
119
|
+
transformers: NonNullable<Options['transformers']>;
|
|
120
|
+
override: NonNullable<Options['override']>;
|
|
121
|
+
seed: NonNullable<Options['seed']> | undefined;
|
|
122
|
+
mapper: NonNullable<Options['mapper']>;
|
|
123
|
+
regexGenerator: NonNullable<Options['regexGenerator']>;
|
|
124
|
+
};
|
|
125
|
+
type PluginFaker = PluginFactoryOptions<'plugin-faker', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
126
|
+
declare module '@kubb/core' {
|
|
127
|
+
interface _Register {
|
|
128
|
+
['@kubb/plugin-faker']: PluginFaker;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
declare const pluginFakerName = "plugin-faker";
|
|
133
|
+
declare const pluginFaker: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginFaker>;
|
|
134
|
+
|
|
135
|
+
export { type PluginFaker, pluginFaker, pluginFakerName };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import * as _kubb_core from '@kubb/core';
|
|
2
|
+
import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
|
|
3
|
+
import * as KubbFile from '@kubb/fs/types';
|
|
4
|
+
import { SchemaObject } from '@kubb/oas';
|
|
5
|
+
import { ResolvePathOptions, Exclude, Include, Override, Schema } from '@kubb/plugin-oas';
|
|
6
|
+
|
|
7
|
+
type Options = {
|
|
8
|
+
output?: {
|
|
9
|
+
/**
|
|
10
|
+
* Relative path to save the Faker mocks.
|
|
11
|
+
* When output is a file it will save all models inside that file else it will create a file per schema item.
|
|
12
|
+
* @default 'mocks'
|
|
13
|
+
*/
|
|
14
|
+
path: string;
|
|
15
|
+
/**
|
|
16
|
+
* Name to be used for the `export * as {{exportAs}} from './'`
|
|
17
|
+
*/
|
|
18
|
+
exportAs?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Add an extension to the generated imports and exports, default it will not use an extension
|
|
21
|
+
*/
|
|
22
|
+
extName?: KubbFile.Extname;
|
|
23
|
+
/**
|
|
24
|
+
* Define what needs to exported, here you can also disable the export of barrel files
|
|
25
|
+
* @default `'barrel'`
|
|
26
|
+
*/
|
|
27
|
+
exportType?: 'barrel' | 'barrelNamed' | false;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Group the Faker mocks based on the provided name.
|
|
31
|
+
*/
|
|
32
|
+
group?: {
|
|
33
|
+
/**
|
|
34
|
+
* Tag will group based on the operation tag inside the Swagger file
|
|
35
|
+
*/
|
|
36
|
+
type: 'tag';
|
|
37
|
+
/**
|
|
38
|
+
* Relative path to save the grouped Faker mocks.
|
|
39
|
+
*
|
|
40
|
+
* `{{tag}}` will be replaced by the current tagName.
|
|
41
|
+
* @example `${output}/{{tag}}Controller` => `mocks/PetController`
|
|
42
|
+
* @default `${output}/{{tag}}Controller`
|
|
43
|
+
*/
|
|
44
|
+
output?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Name to be used for the `export * as {{exportAs}} from './`
|
|
47
|
+
* @default `"{{tag}}Mocks"`
|
|
48
|
+
*/
|
|
49
|
+
exportAs?: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
53
|
+
*/
|
|
54
|
+
exclude?: Array<Exclude>;
|
|
55
|
+
/**
|
|
56
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
57
|
+
*/
|
|
58
|
+
include?: Array<Include>;
|
|
59
|
+
/**
|
|
60
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
61
|
+
*/
|
|
62
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
63
|
+
/**
|
|
64
|
+
* Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
|
|
65
|
+
* @default 'string'
|
|
66
|
+
*/
|
|
67
|
+
dateType?: 'string' | 'date';
|
|
68
|
+
/**
|
|
69
|
+
* Which parser should be used when dateType is set to 'string'.
|
|
70
|
+
* - Schema with format 'date' will use ISO date format (YYYY-MM-DD)
|
|
71
|
+
* - `'dayjs'` will use `dayjs(faker.date.anytime()).format("YYYY-MM-DD")`.
|
|
72
|
+
* - `undefined` will use `faker.date.anytime().toString()`
|
|
73
|
+
* - Schema with format 'time' will use ISO time format (HH:mm:ss[.SSSSSS])
|
|
74
|
+
* - `'dayjs'` will use `dayjs(faker.date.anytime()).format("HH:mm:ss")`.
|
|
75
|
+
* - `undefined` will use `faker.date.anytime().toString()`
|
|
76
|
+
* * @default undefined
|
|
77
|
+
*/
|
|
78
|
+
dateParser?: 'dayjs' | 'moment' | (string & {});
|
|
79
|
+
/**
|
|
80
|
+
* Which type to use when the Swagger/OpenAPI file is not providing more information
|
|
81
|
+
* @default 'any'
|
|
82
|
+
*/
|
|
83
|
+
unknownType?: 'any' | 'unknown';
|
|
84
|
+
transformers?: {
|
|
85
|
+
/**
|
|
86
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
87
|
+
*/
|
|
88
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
89
|
+
/**
|
|
90
|
+
* Receive schema and baseName(propertName) and return FakerMeta array
|
|
91
|
+
* TODO TODO add docs
|
|
92
|
+
* @beta
|
|
93
|
+
*/
|
|
94
|
+
schema?: (props: {
|
|
95
|
+
schema?: SchemaObject;
|
|
96
|
+
name?: string;
|
|
97
|
+
parentName?: string;
|
|
98
|
+
}, defaultSchemas: Schema[]) => Schema[] | undefined;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Choose which generator to use when using Regexp.
|
|
102
|
+
*
|
|
103
|
+
* `'faker'` will use `faker.helpers.fromRegExp(new RegExp(/test/))`
|
|
104
|
+
* `'randexp'` will use `new RandExp(/test/).gen()`
|
|
105
|
+
* @default 'faker'
|
|
106
|
+
*/
|
|
107
|
+
regexGenerator?: 'faker' | 'randexp';
|
|
108
|
+
mapper?: Record<string, string>;
|
|
109
|
+
/**
|
|
110
|
+
* The use of Seed is intended to allow for consistent values in a test.
|
|
111
|
+
*/
|
|
112
|
+
seed?: number | number[];
|
|
113
|
+
};
|
|
114
|
+
type ResolvedOptions = {
|
|
115
|
+
extName: KubbFile.Extname | undefined;
|
|
116
|
+
dateType: NonNullable<Options['dateType']>;
|
|
117
|
+
dateParser: Options['dateParser'];
|
|
118
|
+
unknownType: NonNullable<Options['unknownType']>;
|
|
119
|
+
transformers: NonNullable<Options['transformers']>;
|
|
120
|
+
override: NonNullable<Options['override']>;
|
|
121
|
+
seed: NonNullable<Options['seed']> | undefined;
|
|
122
|
+
mapper: NonNullable<Options['mapper']>;
|
|
123
|
+
regexGenerator: NonNullable<Options['regexGenerator']>;
|
|
124
|
+
};
|
|
125
|
+
type PluginFaker = PluginFactoryOptions<'plugin-faker', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
126
|
+
declare module '@kubb/core' {
|
|
127
|
+
interface _Register {
|
|
128
|
+
['@kubb/plugin-faker']: PluginFaker;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
declare const pluginFakerName = "plugin-faker";
|
|
133
|
+
declare const pluginFaker: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginFaker>;
|
|
134
|
+
|
|
135
|
+
export { type PluginFaker, pluginFaker, pluginFakerName };
|