@kubb/plugin-faker 3.0.0-alpha.14 → 3.0.0-alpha.16
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/dist/chunk-7JKM5LCT.cjs +310 -0
- package/dist/chunk-7JKM5LCT.cjs.map +1 -0
- package/dist/chunk-CJMJFFHG.cjs +110 -0
- package/dist/chunk-CJMJFFHG.cjs.map +1 -0
- package/dist/chunk-JE7K2NAC.js +108 -0
- package/dist/chunk-JE7K2NAC.js.map +1 -0
- package/dist/chunk-Q5K4KJXX.js +304 -0
- package/dist/chunk-Q5K4KJXX.js.map +1 -0
- package/dist/components.cjs +4 -530
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +16 -18
- package/dist/components.d.ts +16 -18
- package/dist/components.js +1 -528
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +13 -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 +12 -430
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -125
- package/dist/index.d.ts +5 -125
- package/dist/index.js +13 -430
- package/dist/index.js.map +1 -1
- package/dist/types-DrJPCRvZ.d.cts +125 -0
- package/dist/types-DrJPCRvZ.d.ts +125 -0
- package/package.json +21 -13
- package/src/components/Faker.tsx +80 -0
- package/src/components/index.ts +1 -2
- package/src/generators/__snapshots__/createPet.ts +26 -0
- package/src/generators/__snapshots__/createPetSeed.ts +30 -0
- package/src/generators/__snapshots__/createPetUnknownTypeAny.ts +26 -0
- package/src/generators/__snapshots__/deletePet.ts +3 -0
- package/src/generators/__snapshots__/enumNames.ts +5 -0
- package/src/generators/__snapshots__/enumVarNames.ts +5 -0
- package/src/generators/__snapshots__/getPets.ts +29 -0
- package/src/generators/__snapshots__/pet.ts +15 -0
- package/src/generators/__snapshots__/petWithDateString.ts +15 -0
- package/src/generators/__snapshots__/petWithDayjs.ts +16 -0
- package/src/generators/__snapshots__/petWithMapper.ts +15 -0
- package/src/generators/__snapshots__/petWithRandExp.ts +16 -0
- package/src/generators/__snapshots__/pets.ts +5 -0
- package/src/generators/__snapshots__/showPetById.ts +29 -0
- package/src/generators/fakerGenerator.tsx +135 -0
- package/src/generators/index.ts +1 -0
- package/src/parser/index.ts +22 -12
- package/src/plugin.ts +7 -10
- package/src/types.ts +17 -17
- package/src/OperationGenerator.tsx +0 -31
- package/src/SchemaGenerator.tsx +0 -31
- package/src/components/OperationSchema.tsx +0 -81
- package/src/components/Schema.tsx +0 -148
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
|
|
2
|
+
import * as KubbFile from '@kubb/fs/types';
|
|
3
|
+
import { SchemaObject } from '@kubb/oas';
|
|
4
|
+
import { ResolvePathOptions, Exclude, Include, Override, Schema } from '@kubb/plugin-oas';
|
|
5
|
+
|
|
6
|
+
type Options = {
|
|
7
|
+
output?: {
|
|
8
|
+
/**
|
|
9
|
+
* Relative path to save the Faker mocks.
|
|
10
|
+
* When output is a file it will save all models inside that file else it will create a file per schema item.
|
|
11
|
+
* @default 'mocks'
|
|
12
|
+
*/
|
|
13
|
+
path: string;
|
|
14
|
+
/**
|
|
15
|
+
* Name to be used for the `export * as {{exportAs}} from './'`
|
|
16
|
+
*/
|
|
17
|
+
exportAs?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Add an extension to the generated imports and exports, default it will not use an extension
|
|
20
|
+
*/
|
|
21
|
+
extName?: KubbFile.Extname;
|
|
22
|
+
/**
|
|
23
|
+
* Define what needs to exported, here you can also disable the export of barrel files
|
|
24
|
+
* @default `'barrel'`
|
|
25
|
+
*/
|
|
26
|
+
exportType?: 'barrel' | 'barrelNamed' | false;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Group the Faker mocks based on the provided name.
|
|
30
|
+
*/
|
|
31
|
+
group?: {
|
|
32
|
+
/**
|
|
33
|
+
* Tag will group based on the operation tag inside the Swagger file
|
|
34
|
+
*/
|
|
35
|
+
type: 'tag';
|
|
36
|
+
/**
|
|
37
|
+
* Relative path to save the grouped Faker mocks.
|
|
38
|
+
*
|
|
39
|
+
* `{{tag}}` will be replaced by the current tagName.
|
|
40
|
+
* @example `${output}/{{tag}}Controller` => `mocks/PetController`
|
|
41
|
+
* @default `${output}/{{tag}}Controller`
|
|
42
|
+
*/
|
|
43
|
+
output?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Name to be used for the `export * as {{exportAs}} from './`
|
|
46
|
+
* @default `"{{tag}}Mocks"`
|
|
47
|
+
*/
|
|
48
|
+
exportAs?: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
52
|
+
*/
|
|
53
|
+
exclude?: Array<Exclude>;
|
|
54
|
+
/**
|
|
55
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
56
|
+
*/
|
|
57
|
+
include?: Array<Include>;
|
|
58
|
+
/**
|
|
59
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
60
|
+
*/
|
|
61
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
62
|
+
/**
|
|
63
|
+
* Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
|
|
64
|
+
* @default 'string'
|
|
65
|
+
*/
|
|
66
|
+
dateType?: 'string' | 'date';
|
|
67
|
+
/**
|
|
68
|
+
* Which parser should be used when dateType is set to 'string'.
|
|
69
|
+
* - Schema with format 'date' will use ISO date format (YYYY-MM-DD)
|
|
70
|
+
* - `'dayjs'` will use `dayjs(faker.date.anytime()).format("YYYY-MM-DD")`.
|
|
71
|
+
* - `undefined` will use `faker.date.anytime().toString()`
|
|
72
|
+
* - Schema with format 'time' will use ISO time format (HH:mm:ss[.SSSSSS])
|
|
73
|
+
* - `'dayjs'` will use `dayjs(faker.date.anytime()).format("HH:mm:ss")`.
|
|
74
|
+
* - `undefined` will use `faker.date.anytime().toString()`
|
|
75
|
+
* * @default 'faker'
|
|
76
|
+
*/
|
|
77
|
+
dateParser?: 'faker' | 'dayjs' | 'moment' | (string & {});
|
|
78
|
+
/**
|
|
79
|
+
* Which type to use when the Swagger/OpenAPI file is not providing more information
|
|
80
|
+
* @default 'any'
|
|
81
|
+
*/
|
|
82
|
+
unknownType?: 'any' | 'unknown';
|
|
83
|
+
/**
|
|
84
|
+
* Choose which generator to use when using Regexp.
|
|
85
|
+
*
|
|
86
|
+
* `'faker'` will use `faker.helpers.fromRegExp(new RegExp(/test/))`
|
|
87
|
+
* `'randexp'` will use `new RandExp(/test/).gen()`
|
|
88
|
+
* @default 'faker'
|
|
89
|
+
*/
|
|
90
|
+
regexGenerator?: 'faker' | 'randexp';
|
|
91
|
+
mapper?: Record<string, string>;
|
|
92
|
+
/**
|
|
93
|
+
* The use of Seed is intended to allow for consistent values in a test.
|
|
94
|
+
*/
|
|
95
|
+
seed?: number | number[];
|
|
96
|
+
transformers?: {
|
|
97
|
+
/**
|
|
98
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
99
|
+
*/
|
|
100
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
101
|
+
/**
|
|
102
|
+
* Receive schema and baseName(propertName) and return FakerMeta array
|
|
103
|
+
* TODO TODO add docs
|
|
104
|
+
* @beta
|
|
105
|
+
*/
|
|
106
|
+
schema?: (props: {
|
|
107
|
+
schema?: SchemaObject;
|
|
108
|
+
name?: string;
|
|
109
|
+
parentName?: string;
|
|
110
|
+
}, defaultSchemas: Schema[]) => Schema[] | undefined;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
type ResolvedOptions = {
|
|
114
|
+
override: NonNullable<Options['override']>;
|
|
115
|
+
dateType: NonNullable<Options['dateType']>;
|
|
116
|
+
dateParser: NonNullable<Options['dateParser']>;
|
|
117
|
+
unknownType: NonNullable<Options['unknownType']>;
|
|
118
|
+
transformers: NonNullable<Options['transformers']>;
|
|
119
|
+
seed: NonNullable<Options['seed']> | undefined;
|
|
120
|
+
mapper: NonNullable<Options['mapper']>;
|
|
121
|
+
regexGenerator: NonNullable<Options['regexGenerator']>;
|
|
122
|
+
};
|
|
123
|
+
type PluginFaker = PluginFactoryOptions<'plugin-faker', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
124
|
+
|
|
125
|
+
export type { Options as O, PluginFaker as P };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
|
|
2
|
+
import * as KubbFile from '@kubb/fs/types';
|
|
3
|
+
import { SchemaObject } from '@kubb/oas';
|
|
4
|
+
import { ResolvePathOptions, Exclude, Include, Override, Schema } from '@kubb/plugin-oas';
|
|
5
|
+
|
|
6
|
+
type Options = {
|
|
7
|
+
output?: {
|
|
8
|
+
/**
|
|
9
|
+
* Relative path to save the Faker mocks.
|
|
10
|
+
* When output is a file it will save all models inside that file else it will create a file per schema item.
|
|
11
|
+
* @default 'mocks'
|
|
12
|
+
*/
|
|
13
|
+
path: string;
|
|
14
|
+
/**
|
|
15
|
+
* Name to be used for the `export * as {{exportAs}} from './'`
|
|
16
|
+
*/
|
|
17
|
+
exportAs?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Add an extension to the generated imports and exports, default it will not use an extension
|
|
20
|
+
*/
|
|
21
|
+
extName?: KubbFile.Extname;
|
|
22
|
+
/**
|
|
23
|
+
* Define what needs to exported, here you can also disable the export of barrel files
|
|
24
|
+
* @default `'barrel'`
|
|
25
|
+
*/
|
|
26
|
+
exportType?: 'barrel' | 'barrelNamed' | false;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Group the Faker mocks based on the provided name.
|
|
30
|
+
*/
|
|
31
|
+
group?: {
|
|
32
|
+
/**
|
|
33
|
+
* Tag will group based on the operation tag inside the Swagger file
|
|
34
|
+
*/
|
|
35
|
+
type: 'tag';
|
|
36
|
+
/**
|
|
37
|
+
* Relative path to save the grouped Faker mocks.
|
|
38
|
+
*
|
|
39
|
+
* `{{tag}}` will be replaced by the current tagName.
|
|
40
|
+
* @example `${output}/{{tag}}Controller` => `mocks/PetController`
|
|
41
|
+
* @default `${output}/{{tag}}Controller`
|
|
42
|
+
*/
|
|
43
|
+
output?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Name to be used for the `export * as {{exportAs}} from './`
|
|
46
|
+
* @default `"{{tag}}Mocks"`
|
|
47
|
+
*/
|
|
48
|
+
exportAs?: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
52
|
+
*/
|
|
53
|
+
exclude?: Array<Exclude>;
|
|
54
|
+
/**
|
|
55
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
56
|
+
*/
|
|
57
|
+
include?: Array<Include>;
|
|
58
|
+
/**
|
|
59
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
60
|
+
*/
|
|
61
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
62
|
+
/**
|
|
63
|
+
* Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
|
|
64
|
+
* @default 'string'
|
|
65
|
+
*/
|
|
66
|
+
dateType?: 'string' | 'date';
|
|
67
|
+
/**
|
|
68
|
+
* Which parser should be used when dateType is set to 'string'.
|
|
69
|
+
* - Schema with format 'date' will use ISO date format (YYYY-MM-DD)
|
|
70
|
+
* - `'dayjs'` will use `dayjs(faker.date.anytime()).format("YYYY-MM-DD")`.
|
|
71
|
+
* - `undefined` will use `faker.date.anytime().toString()`
|
|
72
|
+
* - Schema with format 'time' will use ISO time format (HH:mm:ss[.SSSSSS])
|
|
73
|
+
* - `'dayjs'` will use `dayjs(faker.date.anytime()).format("HH:mm:ss")`.
|
|
74
|
+
* - `undefined` will use `faker.date.anytime().toString()`
|
|
75
|
+
* * @default 'faker'
|
|
76
|
+
*/
|
|
77
|
+
dateParser?: 'faker' | 'dayjs' | 'moment' | (string & {});
|
|
78
|
+
/**
|
|
79
|
+
* Which type to use when the Swagger/OpenAPI file is not providing more information
|
|
80
|
+
* @default 'any'
|
|
81
|
+
*/
|
|
82
|
+
unknownType?: 'any' | 'unknown';
|
|
83
|
+
/**
|
|
84
|
+
* Choose which generator to use when using Regexp.
|
|
85
|
+
*
|
|
86
|
+
* `'faker'` will use `faker.helpers.fromRegExp(new RegExp(/test/))`
|
|
87
|
+
* `'randexp'` will use `new RandExp(/test/).gen()`
|
|
88
|
+
* @default 'faker'
|
|
89
|
+
*/
|
|
90
|
+
regexGenerator?: 'faker' | 'randexp';
|
|
91
|
+
mapper?: Record<string, string>;
|
|
92
|
+
/**
|
|
93
|
+
* The use of Seed is intended to allow for consistent values in a test.
|
|
94
|
+
*/
|
|
95
|
+
seed?: number | number[];
|
|
96
|
+
transformers?: {
|
|
97
|
+
/**
|
|
98
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
99
|
+
*/
|
|
100
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
101
|
+
/**
|
|
102
|
+
* Receive schema and baseName(propertName) and return FakerMeta array
|
|
103
|
+
* TODO TODO add docs
|
|
104
|
+
* @beta
|
|
105
|
+
*/
|
|
106
|
+
schema?: (props: {
|
|
107
|
+
schema?: SchemaObject;
|
|
108
|
+
name?: string;
|
|
109
|
+
parentName?: string;
|
|
110
|
+
}, defaultSchemas: Schema[]) => Schema[] | undefined;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
type ResolvedOptions = {
|
|
114
|
+
override: NonNullable<Options['override']>;
|
|
115
|
+
dateType: NonNullable<Options['dateType']>;
|
|
116
|
+
dateParser: NonNullable<Options['dateParser']>;
|
|
117
|
+
unknownType: NonNullable<Options['unknownType']>;
|
|
118
|
+
transformers: NonNullable<Options['transformers']>;
|
|
119
|
+
seed: NonNullable<Options['seed']> | undefined;
|
|
120
|
+
mapper: NonNullable<Options['mapper']>;
|
|
121
|
+
regexGenerator: NonNullable<Options['regexGenerator']>;
|
|
122
|
+
};
|
|
123
|
+
type PluginFaker = PluginFactoryOptions<'plugin-faker', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
124
|
+
|
|
125
|
+
export type { Options as O, PluginFaker as P };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-faker",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.16",
|
|
4
4
|
"description": "Generator plugin-faker",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"faker",
|
|
@@ -28,6 +28,11 @@
|
|
|
28
28
|
"require": "./dist/index.cjs",
|
|
29
29
|
"default": "./dist/index.cjs"
|
|
30
30
|
},
|
|
31
|
+
"./generators": {
|
|
32
|
+
"import": "./dist/generators.js",
|
|
33
|
+
"require": "./dist/generators.cjs",
|
|
34
|
+
"default": "./dist/generators.cjs"
|
|
35
|
+
},
|
|
31
36
|
"./components": {
|
|
32
37
|
"import": "./dist/components.js",
|
|
33
38
|
"require": "./dist/components.cjs",
|
|
@@ -43,6 +48,9 @@
|
|
|
43
48
|
"*": {
|
|
44
49
|
"components": [
|
|
45
50
|
"./dist/components.d.ts"
|
|
51
|
+
],
|
|
52
|
+
"generators": [
|
|
53
|
+
"./dist/generators.d.ts"
|
|
46
54
|
]
|
|
47
55
|
}
|
|
48
56
|
},
|
|
@@ -53,25 +61,25 @@
|
|
|
53
61
|
"!/**/__tests__/**"
|
|
54
62
|
],
|
|
55
63
|
"dependencies": {
|
|
56
|
-
"@kubb/core": "3.0.0-alpha.
|
|
57
|
-
"@kubb/fs": "3.0.0-alpha.
|
|
58
|
-
"@kubb/oas": "3.0.0-alpha.
|
|
59
|
-
"@kubb/parser-ts": "3.0.0-alpha.
|
|
60
|
-
"@kubb/plugin-oas": "3.0.0-alpha.
|
|
61
|
-
"@kubb/plugin-ts": "3.0.0-alpha.
|
|
62
|
-
"@kubb/react": "3.0.0-alpha.
|
|
64
|
+
"@kubb/core": "3.0.0-alpha.16",
|
|
65
|
+
"@kubb/fs": "3.0.0-alpha.16",
|
|
66
|
+
"@kubb/oas": "3.0.0-alpha.16",
|
|
67
|
+
"@kubb/parser-ts": "3.0.0-alpha.16",
|
|
68
|
+
"@kubb/plugin-oas": "3.0.0-alpha.16",
|
|
69
|
+
"@kubb/plugin-ts": "3.0.0-alpha.16",
|
|
70
|
+
"@kubb/react": "3.0.0-alpha.16"
|
|
63
71
|
},
|
|
64
72
|
"devDependencies": {
|
|
65
73
|
"@types/react": "^18.3.5",
|
|
66
74
|
"react": "^18.3.1",
|
|
67
75
|
"tsup": "^8.2.4",
|
|
68
|
-
"typescript": "^5.
|
|
69
|
-
"@kubb/config-biome": "3.0.0-alpha.
|
|
70
|
-
"@kubb/config-ts": "3.0.0-alpha.
|
|
71
|
-
"@kubb/config-tsup": "3.0.0-alpha.
|
|
76
|
+
"typescript": "^5.6.2",
|
|
77
|
+
"@kubb/config-biome": "3.0.0-alpha.16",
|
|
78
|
+
"@kubb/config-ts": "3.0.0-alpha.16",
|
|
79
|
+
"@kubb/config-tsup": "3.0.0-alpha.16"
|
|
72
80
|
},
|
|
73
81
|
"peerDependencies": {
|
|
74
|
-
"@kubb/react": "3.0.0-alpha.
|
|
82
|
+
"@kubb/react": "3.0.0-alpha.16"
|
|
75
83
|
},
|
|
76
84
|
"engines": {
|
|
77
85
|
"node": ">=20"
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { File, Function, FunctionParams } from '@kubb/react'
|
|
2
|
+
|
|
3
|
+
import transformers from '@kubb/core/transformers'
|
|
4
|
+
import type { Schema } from '@kubb/plugin-oas'
|
|
5
|
+
import type { KubbNode } from '@kubb/react/types'
|
|
6
|
+
import * as parserFaker from '../parser/index.ts'
|
|
7
|
+
import type { PluginFaker } from '../types.ts'
|
|
8
|
+
|
|
9
|
+
type Props = {
|
|
10
|
+
name: string
|
|
11
|
+
typeName: string
|
|
12
|
+
tree: Array<Schema>
|
|
13
|
+
seed?: PluginFaker['options']['seed']
|
|
14
|
+
description?: string
|
|
15
|
+
regexGenerator?: PluginFaker['options']['regexGenerator']
|
|
16
|
+
mapper?: PluginFaker['options']['mapper']
|
|
17
|
+
dateParser?: PluginFaker['options']['dateParser']
|
|
18
|
+
canOverride: boolean
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function Faker({ tree, description, name, typeName, seed, regexGenerator, canOverride, mapper, dateParser }: Props): KubbNode {
|
|
22
|
+
const fakerText = parserFaker.joinItems(
|
|
23
|
+
tree
|
|
24
|
+
.map((schema) =>
|
|
25
|
+
parserFaker.parse(undefined, schema, {
|
|
26
|
+
name,
|
|
27
|
+
typeName,
|
|
28
|
+
seed,
|
|
29
|
+
regexGenerator,
|
|
30
|
+
mapper,
|
|
31
|
+
canOverride,
|
|
32
|
+
dateParser,
|
|
33
|
+
}),
|
|
34
|
+
)
|
|
35
|
+
.filter(Boolean),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
let fakerDefaultOverride: '' | '[]' | '{}' | undefined = undefined
|
|
39
|
+
let fakerTextWithOverride = fakerText
|
|
40
|
+
|
|
41
|
+
if (canOverride && fakerText.startsWith('{')) {
|
|
42
|
+
fakerDefaultOverride = '{}'
|
|
43
|
+
fakerTextWithOverride = `{
|
|
44
|
+
...${fakerText},
|
|
45
|
+
...data
|
|
46
|
+
}`
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (canOverride && fakerText.startsWith('faker.helpers.arrayElements')) {
|
|
50
|
+
fakerDefaultOverride = '[]'
|
|
51
|
+
fakerTextWithOverride = `[
|
|
52
|
+
...${fakerText},
|
|
53
|
+
...data
|
|
54
|
+
]`
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const params = FunctionParams.factory({
|
|
58
|
+
data: fakerDefaultOverride
|
|
59
|
+
? {
|
|
60
|
+
type: `NonNullable<Partial<${typeName}>>`,
|
|
61
|
+
default: fakerDefaultOverride,
|
|
62
|
+
}
|
|
63
|
+
: undefined,
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<File.Source name={name} isExportable isIndexable>
|
|
68
|
+
<Function
|
|
69
|
+
export
|
|
70
|
+
name={name}
|
|
71
|
+
JSDoc={{ comments: [description ? `@description ${transformers.jsStringEscape(description)}` : undefined].filter(Boolean) }}
|
|
72
|
+
params={params.toConstructor()}
|
|
73
|
+
>
|
|
74
|
+
{seed ? `faker.seed(${JSON.stringify(seed)})` : undefined}
|
|
75
|
+
<br />
|
|
76
|
+
{`return ${fakerTextWithOverride}`}
|
|
77
|
+
</Function>
|
|
78
|
+
</File.Source>
|
|
79
|
+
)
|
|
80
|
+
}
|
package/src/components/index.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { Schema } from './Schema.tsx'
|
|
1
|
+
export { Faker } from './Faker.tsx'
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description Null response
|
|
5
|
+
*/
|
|
6
|
+
export function createPets201() {
|
|
7
|
+
return unknown
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @description unexpected error
|
|
12
|
+
*/
|
|
13
|
+
export function createPetsError() {
|
|
14
|
+
return error()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createPetsMutationRequest(data: NonNullable<Partial<CreatePetsMutationRequest>> = {}) {
|
|
18
|
+
return {
|
|
19
|
+
...{ name: faker.string.alpha(), tag: faker.string.alpha() },
|
|
20
|
+
...data,
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function createPetsMutationResponse() {
|
|
25
|
+
return unknown
|
|
26
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description Null response
|
|
5
|
+
*/
|
|
6
|
+
export function createPets201() {
|
|
7
|
+
faker.seed([222])
|
|
8
|
+
return unknown
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @description unexpected error
|
|
13
|
+
*/
|
|
14
|
+
export function createPetsError() {
|
|
15
|
+
faker.seed([222])
|
|
16
|
+
return error()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function createPetsMutationRequest(data: NonNullable<Partial<CreatePetsMutationRequest>> = {}) {
|
|
20
|
+
faker.seed([222])
|
|
21
|
+
return {
|
|
22
|
+
...{ name: faker.string.alpha(), tag: faker.string.alpha() },
|
|
23
|
+
...data,
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function createPetsMutationResponse() {
|
|
28
|
+
faker.seed([222])
|
|
29
|
+
return unknown
|
|
30
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description Null response
|
|
5
|
+
*/
|
|
6
|
+
export function createPets201() {
|
|
7
|
+
return undefined
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @description unexpected error
|
|
12
|
+
*/
|
|
13
|
+
export function createPetsError() {
|
|
14
|
+
return error()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createPetsMutationRequest(data: NonNullable<Partial<CreatePetsMutationRequest>> = {}) {
|
|
18
|
+
return {
|
|
19
|
+
...{ name: faker.string.alpha(), tag: faker.string.alpha() },
|
|
20
|
+
...data,
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function createPetsMutationResponse() {
|
|
25
|
+
return undefined
|
|
26
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker'
|
|
2
|
+
|
|
3
|
+
export function listPetsQueryParams(data: NonNullable<Partial<ListPetsQueryParams>> = {}) {
|
|
4
|
+
return {
|
|
5
|
+
...{ limit: faker.string.alpha() },
|
|
6
|
+
...data,
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @description A paged array of pets
|
|
12
|
+
*/
|
|
13
|
+
export function listPets200() {
|
|
14
|
+
return pets()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @description unexpected error
|
|
19
|
+
*/
|
|
20
|
+
export function listPetsError() {
|
|
21
|
+
return error()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @description A paged array of pets
|
|
26
|
+
*/
|
|
27
|
+
export function listPetsQueryResponse() {
|
|
28
|
+
return pets()
|
|
29
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker'
|
|
2
|
+
|
|
3
|
+
export function pet(data: NonNullable<Partial<Pet>> = {}) {
|
|
4
|
+
return {
|
|
5
|
+
...{
|
|
6
|
+
id: faker.number.int(),
|
|
7
|
+
name: faker.string.alpha(),
|
|
8
|
+
tag: faker.string.alpha(),
|
|
9
|
+
code: faker.helpers.arrayElement<any>([faker.string.alpha(), faker.helpers.fromRegExp(new RegExp('\\b[1-9]\\b'))]),
|
|
10
|
+
shipDate: faker.date.anytime(),
|
|
11
|
+
shipTime: faker.date.anytime(),
|
|
12
|
+
},
|
|
13
|
+
...data,
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker'
|
|
2
|
+
|
|
3
|
+
export function pet(data: NonNullable<Partial<Pet>> = {}) {
|
|
4
|
+
return {
|
|
5
|
+
...{
|
|
6
|
+
id: faker.number.int(),
|
|
7
|
+
name: faker.string.alpha(),
|
|
8
|
+
tag: faker.string.alpha(),
|
|
9
|
+
code: faker.helpers.arrayElement<any>([faker.string.alpha(), faker.helpers.fromRegExp(new RegExp('\\b[1-9]\\b'))]),
|
|
10
|
+
shipDate: faker.date.anytime().toString(),
|
|
11
|
+
shipTime: faker.date.anytime().toString(),
|
|
12
|
+
},
|
|
13
|
+
...data,
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import dayjs from 'dayjs'
|
|
2
|
+
import { faker } from '@faker-js/faker'
|
|
3
|
+
|
|
4
|
+
export function pet(data: NonNullable<Partial<Pet>> = {}) {
|
|
5
|
+
return {
|
|
6
|
+
...{
|
|
7
|
+
id: faker.number.int(),
|
|
8
|
+
name: faker.string.alpha(),
|
|
9
|
+
tag: faker.string.alpha(),
|
|
10
|
+
code: faker.helpers.arrayElement<any>([faker.string.alpha(), faker.helpers.fromRegExp(new RegExp('\\b[1-9]\\b'))]),
|
|
11
|
+
shipDate: dayjs(faker.date.anytime()).format('YYYY-MM-DD'),
|
|
12
|
+
shipTime: dayjs(faker.date.anytime()).format('HH:mm:ss'),
|
|
13
|
+
},
|
|
14
|
+
...data,
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker'
|
|
2
|
+
|
|
3
|
+
export function pet(data: NonNullable<Partial<Pet>> = {}) {
|
|
4
|
+
return {
|
|
5
|
+
...{
|
|
6
|
+
id: faker.string.fromCharacters('abc'),
|
|
7
|
+
name: faker.string.alpha({ casing: 'lower' }),
|
|
8
|
+
tag: faker.string.alpha(),
|
|
9
|
+
code: faker.helpers.arrayElement<any>([faker.string.alpha(), faker.helpers.fromRegExp(new RegExp('\\b[1-9]\\b'))]),
|
|
10
|
+
shipDate: faker.date.anytime(),
|
|
11
|
+
shipTime: faker.date.anytime(),
|
|
12
|
+
},
|
|
13
|
+
...data,
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import RandExp from 'randexp'
|
|
2
|
+
import { faker } from '@faker-js/faker'
|
|
3
|
+
|
|
4
|
+
export function pet(data: NonNullable<Partial<Pet>> = {}) {
|
|
5
|
+
return {
|
|
6
|
+
...{
|
|
7
|
+
id: faker.number.int(),
|
|
8
|
+
name: faker.string.alpha(),
|
|
9
|
+
tag: faker.string.alpha(),
|
|
10
|
+
code: faker.helpers.arrayElement<any>([faker.string.alpha(), new RandExp('\\b[1-9]\\b').gen()]),
|
|
11
|
+
shipDate: faker.date.anytime(),
|
|
12
|
+
shipTime: faker.date.anytime(),
|
|
13
|
+
},
|
|
14
|
+
...data,
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker'
|
|
2
|
+
|
|
3
|
+
export function showPetByIdPathParams(data: NonNullable<Partial<ShowPetByIdPathParams>> = {}) {
|
|
4
|
+
return {
|
|
5
|
+
...{ petId: faker.string.alpha(), testId: faker.string.alpha() },
|
|
6
|
+
...data,
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @description Expected response to a valid request
|
|
12
|
+
*/
|
|
13
|
+
export function showPetById200() {
|
|
14
|
+
return pet()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @description unexpected error
|
|
19
|
+
*/
|
|
20
|
+
export function showPetByIdError() {
|
|
21
|
+
return error()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @description Expected response to a valid request
|
|
26
|
+
*/
|
|
27
|
+
export function showPetByIdQueryResponse() {
|
|
28
|
+
return pet()
|
|
29
|
+
}
|