@kubb/plugin-faker 3.0.0-alpha.3 → 3.0.0-alpha.30

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 (55) hide show
  1. package/README.md +13 -4
  2. package/dist/chunk-HTZ2R6MK.js +305 -0
  3. package/dist/chunk-HTZ2R6MK.js.map +1 -0
  4. package/dist/chunk-KBSFZ5OP.cjs +311 -0
  5. package/dist/chunk-KBSFZ5OP.cjs.map +1 -0
  6. package/dist/chunk-QFJUM25Z.js +113 -0
  7. package/dist/chunk-QFJUM25Z.js.map +1 -0
  8. package/dist/chunk-U6LOSTOE.cjs +115 -0
  9. package/dist/chunk-U6LOSTOE.cjs.map +1 -0
  10. package/dist/components.cjs +6 -565
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +15 -18
  13. package/dist/components.d.ts +15 -18
  14. package/dist/components.js +2 -570
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +13 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +8 -0
  19. package/dist/generators.d.ts +8 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +48 -504
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +4 -125
  25. package/dist/index.d.ts +4 -125
  26. package/dist/index.js +31 -494
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-DXoBXKVI.d.cts +112 -0
  29. package/dist/types-DXoBXKVI.d.ts +112 -0
  30. package/package.json +20 -16
  31. package/src/components/Faker.tsx +80 -0
  32. package/src/components/index.ts +1 -2
  33. package/src/generators/__snapshots__/createPet.ts +26 -0
  34. package/src/generators/__snapshots__/createPetSeed.ts +30 -0
  35. package/src/generators/__snapshots__/createPetUnknownTypeAny.ts +26 -0
  36. package/src/generators/__snapshots__/deletePet.ts +3 -0
  37. package/src/generators/__snapshots__/enumNames.ts +5 -0
  38. package/src/generators/__snapshots__/enumVarNames.ts +5 -0
  39. package/src/generators/__snapshots__/getPets.ts +29 -0
  40. package/src/generators/__snapshots__/pet.ts +8 -0
  41. package/src/generators/__snapshots__/petWithDateString.ts +8 -0
  42. package/src/generators/__snapshots__/petWithDayjs.ts +9 -0
  43. package/src/generators/__snapshots__/petWithMapper.ts +8 -0
  44. package/src/generators/__snapshots__/petWithRandExp.ts +9 -0
  45. package/src/generators/__snapshots__/pets.ts +8 -0
  46. package/src/generators/__snapshots__/showPetById.ts +29 -0
  47. package/src/generators/fakerGenerator.tsx +140 -0
  48. package/src/generators/index.ts +1 -0
  49. package/src/parser/index.ts +25 -14
  50. package/src/plugin.ts +19 -35
  51. package/src/types.ts +27 -48
  52. package/src/OperationGenerator.tsx +0 -31
  53. package/src/SchemaGenerator.tsx +0 -31
  54. package/src/components/OperationSchema.tsx +0 -84
  55. package/src/components/Schema.tsx +0 -146
@@ -0,0 +1,8 @@
1
+ import { faker } from "@faker-js/faker";
2
+
3
+ export function pet(data: NonNullable<Partial<Pet>> = {}) {
4
+ return {
5
+ ...{ "id": faker.string.fromCharacters("abc"), "name": faker.string.alpha({ casing: "lower" }), "tag": faker.string.alpha(), "code": faker.helpers.arrayElement<any>([faker.string.alpha(), faker.helpers.fromRegExp(new RegExp("\\b[1-9]\\b"))]), "shipDate": faker.date.anytime(), "shipTime": faker.date.anytime() },
6
+ ...data
7
+ };
8
+ }
@@ -0,0 +1,9 @@
1
+ import RandExp from "randexp";
2
+ import { faker } from "@faker-js/faker";
3
+
4
+ export function pet(data: NonNullable<Partial<Pet>> = {}) {
5
+ return {
6
+ ...{ "id": faker.number.int(), "name": faker.string.alpha(), "tag": faker.string.alpha(), "code": faker.helpers.arrayElement<any>([faker.string.alpha(), new RandExp("\\b[1-9]\\b").gen()]), "shipDate": faker.date.anytime(), "shipTime": faker.date.anytime() },
7
+ ...data
8
+ };
9
+ }
@@ -0,0 +1,8 @@
1
+ import { faker } from "@faker-js/faker";
2
+
3
+ export function pets(data: NonNullable<Partial<Pets>> = []) {
4
+ return [
5
+ ...faker.helpers.arrayElements([pet()]) as any,
6
+ ...data
7
+ ];
8
+ }
@@ -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
+ }
@@ -0,0 +1,140 @@
1
+ import { type OperationSchema as OperationSchemaType, SchemaGenerator, createReactGenerator, schemaKeywords } from '@kubb/plugin-oas'
2
+ import { Oas } from '@kubb/plugin-oas/components'
3
+ import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'
4
+ import { pluginTsName } from '@kubb/plugin-ts'
5
+ import { File, useApp } from '@kubb/react'
6
+ import { Faker } from '../components'
7
+ import type { PluginFaker } from '../types'
8
+
9
+ export const fakerGenerator = createReactGenerator<PluginFaker>({
10
+ name: 'faker',
11
+ Operation({ operation, options }) {
12
+ const { dateParser, regexGenerator, seed, mapper } = options
13
+
14
+ const { plugin, pluginManager, mode } = useApp<PluginFaker>()
15
+ const oas = useOas()
16
+ const { getSchemas, getFile } = useOperationManager()
17
+ const schemaManager = useSchemaManager()
18
+
19
+ const file = getFile(operation)
20
+ const schemas = getSchemas(operation)
21
+ const schemaGenerator = new SchemaGenerator(options, {
22
+ oas,
23
+ plugin,
24
+ pluginManager,
25
+ mode,
26
+ override: options.override,
27
+ })
28
+
29
+ const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]
30
+ .flat()
31
+ .filter(Boolean)
32
+
33
+ const mapOperationSchema = ({ name, schema, description, ...options }: OperationSchemaType, i: number) => {
34
+ const tree = schemaGenerator.parse({ schema, name })
35
+ const imports = schemaManager.getImports(tree)
36
+
37
+ const faker = {
38
+ name: schemaManager.getName(name, { type: 'function' }),
39
+ file: schemaManager.getFile(name),
40
+ }
41
+
42
+ const type = {
43
+ name: schemaManager.getName(name, { type: 'type', pluginKey: [pluginTsName] }),
44
+ file: schemaManager.getFile(options.operationName || name, { pluginKey: [pluginTsName], tag: options.operation?.getTags()[0]?.name }),
45
+ }
46
+
47
+ const canOverride = tree.some(
48
+ ({ keyword }) =>
49
+ keyword === schemaKeywords.array ||
50
+ keyword === schemaKeywords.and ||
51
+ keyword === schemaKeywords.object ||
52
+ keyword === schemaKeywords.union ||
53
+ keyword === schemaKeywords.tuple,
54
+ )
55
+
56
+ return (
57
+ <Oas.Schema key={i} name={name} value={schema} tree={tree}>
58
+ {canOverride && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}
59
+ {imports.map((imp, index) => (
60
+ <File.Import key={index} root={file.path} path={imp.path} name={imp.name} />
61
+ ))}
62
+ <Faker
63
+ name={faker.name}
64
+ typeName={type.name}
65
+ description={description}
66
+ tree={tree}
67
+ regexGenerator={regexGenerator}
68
+ dateParser={dateParser}
69
+ mapper={mapper}
70
+ seed={seed}
71
+ canOverride={canOverride}
72
+ />
73
+ </Oas.Schema>
74
+ )
75
+ }
76
+
77
+ return (
78
+ <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>
79
+ <File.Import name={['faker']} path="@faker-js/faker" />
80
+ {regexGenerator === 'randexp' && <File.Import name={'RandExp'} path={'randexp'} />}
81
+ {dateParser !== 'faker' && <File.Import path={dateParser} name={dateParser} />}
82
+ {operationSchemas.map(mapOperationSchema)}
83
+ </File>
84
+ )
85
+ },
86
+ Schema({ schema, options }) {
87
+ const { dateParser, regexGenerator, seed, mapper } = options
88
+
89
+ const { getName, getFile, getImports } = useSchemaManager()
90
+ const {
91
+ plugin: {
92
+ options: { output },
93
+ },
94
+ } = useApp<PluginFaker>()
95
+ const imports = getImports(schema.tree)
96
+
97
+ const faker = {
98
+ name: getName(schema.name, { type: 'function' }),
99
+ file: getFile(schema.name),
100
+ }
101
+
102
+ const type = {
103
+ name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),
104
+ file: getFile(schema.name, { pluginKey: [pluginTsName] }),
105
+ }
106
+
107
+ const canOverride = schema.tree.some(
108
+ ({ keyword }) =>
109
+ keyword === schemaKeywords.array ||
110
+ keyword === schemaKeywords.and ||
111
+ keyword === schemaKeywords.object ||
112
+ keyword === schemaKeywords.union ||
113
+ keyword === schemaKeywords.tuple,
114
+ )
115
+
116
+ return (
117
+ <File baseName={faker.file.baseName} path={faker.file.path} meta={faker.file.meta} banner={output?.banner} footer={output?.footer}>
118
+ <File.Import name={['faker']} path="@faker-js/faker" />
119
+ {regexGenerator === 'randexp' && <File.Import name={'RandExp'} path={'randexp'} />}
120
+ {dateParser !== 'faker' && <File.Import path={dateParser} name={dateParser} />}
121
+ <File.Import isTypeOnly root={faker.file.path} path={type.file.path} name={[type.name]} />
122
+ {imports.map((imp, index) => (
123
+ <File.Import key={index} root={faker.file.path} path={imp.path} name={imp.name} />
124
+ ))}
125
+
126
+ <Faker
127
+ name={faker.name}
128
+ typeName={type.name}
129
+ description={schema.value.description}
130
+ tree={schema.tree}
131
+ regexGenerator={regexGenerator}
132
+ dateParser={dateParser}
133
+ mapper={mapper}
134
+ seed={seed}
135
+ canOverride={canOverride}
136
+ />
137
+ </File>
138
+ )
139
+ },
140
+ })
@@ -0,0 +1 @@
1
+ export { fakerGenerator } from './fakerGenerator.tsx'
@@ -4,7 +4,7 @@ import { SchemaGenerator, isKeyword, schemaKeywords } from '@kubb/plugin-oas'
4
4
  import type { Schema, SchemaKeywordBase, SchemaKeywordMapper, SchemaMapper } from '@kubb/plugin-oas'
5
5
  import type { Options } from '../types.ts'
6
6
 
7
- export const fakerKeywordMapper = {
7
+ const fakerKeywordMapper = {
8
8
  any: () => 'undefined',
9
9
  unknown: () => 'unknown',
10
10
  number: (min?: number, max?: number) => {
@@ -68,13 +68,18 @@ export const fakerKeywordMapper = {
68
68
  * Type `'string'` ISO date format (YYYY-MM-DD)
69
69
  * @default ISO date format (YYYY-MM-DD)
70
70
  */
71
- date: (type: 'date' | 'string' = 'string', parser?: string) => {
71
+ date: (type: 'date' | 'string' = 'string', parser: Options['dateParser'] = 'faker') => {
72
72
  if (type === 'string') {
73
- if (parser) {
73
+ if (parser !== 'faker') {
74
74
  return `${parser}(faker.date.anytime()).format("YYYY-MM-DD")`
75
75
  }
76
76
  return 'faker.date.anytime().toString()'
77
77
  }
78
+
79
+ if (parser !== 'faker') {
80
+ throw new Error(`type '${type}' and parser '${parser}' can not work together`)
81
+ }
82
+
78
83
  return 'faker.date.anytime()'
79
84
  },
80
85
  /**
@@ -82,13 +87,18 @@ export const fakerKeywordMapper = {
82
87
  * Type `'string'` ISO time format (HH:mm:ss[.SSSSSS])
83
88
  * @default ISO time format (HH:mm:ss[.SSSSSS])
84
89
  */
85
- time: (type: 'date' | 'string' = 'string', parser?: string) => {
90
+ time: (type: 'date' | 'string' = 'string', parser: Options['dateParser'] = 'faker') => {
86
91
  if (type === 'string') {
87
- if (parser) {
92
+ if (parser !== 'faker') {
88
93
  return `${parser}(faker.date.anytime()).format("HH:mm:ss")`
89
94
  }
90
95
  return 'faker.date.anytime().toString()'
91
96
  }
97
+
98
+ if (parser !== 'faker') {
99
+ throw new Error(`type '${type}' and parser '${parser}' can not work together`)
100
+ }
101
+
92
102
  return 'faker.date.anytime()'
93
103
  },
94
104
  uuid: () => 'faker.string.uuid()',
@@ -107,7 +117,7 @@ export const fakerKeywordMapper = {
107
117
  lastName: () => 'faker.person.lastName()',
108
118
  password: () => 'faker.internet.password()',
109
119
  phone: () => 'faker.phone.number()',
110
- blob: () => 'faker.image.imageUrl() as unknown as Blob',
120
+ blob: () => 'faker.image.url() as unknown as Blob',
111
121
  default: undefined,
112
122
  describe: undefined,
113
123
  const: (value?: string | number) => (value as string) ?? '',
@@ -117,6 +127,7 @@ export const fakerKeywordMapper = {
117
127
  nullish: undefined,
118
128
  optional: undefined,
119
129
  readOnly: undefined,
130
+ writeOnly: undefined,
120
131
  strict: undefined,
121
132
  deprecated: undefined,
122
133
  example: undefined,
@@ -155,7 +166,7 @@ type ParserOptions = {
155
166
 
156
167
  seed?: number | number[]
157
168
  regexGenerator?: 'faker' | 'randexp'
158
- withData?: boolean
169
+ canOverride?: boolean
159
170
  dateParser?: Options['dateParser']
160
171
  mapper?: Record<string, string>
161
172
  }
@@ -168,15 +179,15 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
168
179
  }
169
180
 
170
181
  if (isKeyword(current, schemaKeywords.union)) {
171
- return fakerKeywordMapper.union(current.args.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean))
182
+ return fakerKeywordMapper.union(current.args.map((schema) => parse(current, schema, { ...options, canOverride: false })).filter(Boolean))
172
183
  }
173
184
 
174
185
  if (isKeyword(current, schemaKeywords.and)) {
175
- return fakerKeywordMapper.and(current.args.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean))
186
+ return fakerKeywordMapper.and(current.args.map((schema) => parse(current, schema, { ...options, canOverride: false })).filter(Boolean))
176
187
  }
177
188
 
178
189
  if (isKeyword(current, schemaKeywords.array)) {
179
- return fakerKeywordMapper.array(current.args.items.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean))
190
+ return fakerKeywordMapper.array(current.args.items.map((schema) => parse(current, schema, { ...options, canOverride: false })).filter(Boolean))
180
191
  }
181
192
 
182
193
  if (isKeyword(current, schemaKeywords.enum)) {
@@ -195,7 +206,7 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
195
206
  throw new Error(`Name not defined for keyword ${current.keyword}`)
196
207
  }
197
208
 
198
- if (options.withData) {
209
+ if (options.canOverride) {
199
210
  return `${current.args.name}(data)`
200
211
  }
201
212
 
@@ -220,7 +231,7 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
220
231
  return `"${name}": ${joinItems(
221
232
  schemas
222
233
  .sort(schemaKeywordsorter)
223
- .map((schema) => parse(current, schema, { ...options, withData: false }))
234
+ .map((schema) => parse(current, schema, { ...options, canOverride: false }))
224
235
  .filter(Boolean),
225
236
  )}`
226
237
  })
@@ -231,10 +242,10 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
231
242
 
232
243
  if (isKeyword(current, schemaKeywords.tuple)) {
233
244
  if (Array.isArray(current.args.items)) {
234
- return fakerKeywordMapper.tuple(current.args.items.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean))
245
+ return fakerKeywordMapper.tuple(current.args.items.map((schema) => parse(current, schema, { ...options, canOverride: false })).filter(Boolean))
235
246
  }
236
247
 
237
- return parse(current, current.args.items, { ...options, withData: false })
248
+ return parse(current, current.args.items, { ...options, canOverride: false })
238
249
  }
239
250
 
240
251
  if (isKeyword(current, schemaKeywords.const)) {
package/src/plugin.ts CHANGED
@@ -3,22 +3,20 @@ import path from 'node:path'
3
3
  import { FileManager, PluginManager, createPlugin } from '@kubb/core'
4
4
  import { camelCase } from '@kubb/core/transformers'
5
5
  import { renderTemplate } from '@kubb/core/utils'
6
- import { pluginOasName } from '@kubb/plugin-oas'
7
- import { getGroupedByTagFiles } from '@kubb/plugin-oas/utils'
8
- import { pluginTsName } from '@kubb/plugin-ts'
6
+ import { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'
9
7
 
10
- import { OperationGenerator } from './OperationGenerator.tsx'
11
- import { SchemaGenerator } from './SchemaGenerator.tsx'
8
+ import { pluginTsName } from '@kubb/plugin-ts'
12
9
 
13
10
  import type { Plugin } from '@kubb/core'
14
11
  import type { PluginOas } from '@kubb/plugin-oas'
12
+ import { fakerGenerator } from './generators/fakerGenerator.tsx'
15
13
  import type { PluginFaker } from './types.ts'
16
14
 
17
15
  export const pluginFakerName = 'plugin-faker' satisfies PluginFaker['name']
18
16
 
19
17
  export const pluginFaker = createPlugin<PluginFaker>((options) => {
20
18
  const {
21
- output = { path: 'mocks' },
19
+ output = { path: 'mocks', barrelType: 'named' },
22
20
  seed,
23
21
  group,
24
22
  exclude = [],
@@ -26,9 +24,10 @@ export const pluginFaker = createPlugin<PluginFaker>((options) => {
26
24
  override = [],
27
25
  transformers = {},
28
26
  mapper = {},
29
- dateType = 'string',
30
27
  unknownType = 'any',
31
- dateParser,
28
+ dateType = 'string',
29
+ dateParser = 'faker',
30
+ generators = [fakerGenerator].filter(Boolean),
32
31
  regexGenerator = 'faker',
33
32
  } = options
34
33
  const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`
@@ -36,10 +35,10 @@ export const pluginFaker = createPlugin<PluginFaker>((options) => {
36
35
  return {
37
36
  name: pluginFakerName,
38
37
  options: {
39
- extName: output.extName,
38
+ output,
40
39
  transformers,
41
- dateType,
42
40
  seed,
41
+ dateType,
43
42
  unknownType,
44
43
  dateParser,
45
44
  mapper,
@@ -97,7 +96,7 @@ export const pluginFaker = createPlugin<PluginFaker>((options) => {
97
96
  output: output.path,
98
97
  })
99
98
 
100
- const schemaFiles = await schemaGenerator.build()
99
+ const schemaFiles = await schemaGenerator.build(...generators)
101
100
  await this.addFile(...schemaFiles)
102
101
 
103
102
  const operationGenerator = new OperationGenerator(this.plugin.options, {
@@ -111,36 +110,21 @@ export const pluginFaker = createPlugin<PluginFaker>((options) => {
111
110
  mode,
112
111
  })
113
112
 
114
- const operationFiles = await operationGenerator.build()
113
+ const operationFiles = await operationGenerator.build(...generators)
115
114
  await this.addFile(...operationFiles)
116
- },
117
- async buildEnd() {
118
- if (this.config.output.write === false) {
119
- return
120
- }
121
-
122
- const root = path.resolve(this.config.root, this.config.output.path)
123
115
 
124
- if (group?.type === 'tag') {
125
- const rootFiles = await getGroupedByTagFiles({
126
- logger: this.logger,
127
- files: this.fileManager.files,
128
- plugin: this.plugin,
129
- template,
130
- exportAs: group.exportAs || '{{tag}}Mocks',
131
- root,
132
- output,
133
- })
134
-
135
- await this.addFile(...rootFiles)
136
- }
137
-
138
- await this.fileManager.addIndexes({
116
+ const barrelFiles = await this.fileManager.getBarrelFiles({
117
+ type: output.barrelType ?? 'named',
139
118
  root,
140
119
  output,
141
- meta: { pluginKey: this.plugin.key },
120
+ files: this.fileManager.files,
121
+ meta: {
122
+ pluginKey: this.plugin.key,
123
+ },
142
124
  logger: this.logger,
143
125
  })
126
+
127
+ await this.addFile(...barrelFiles)
144
128
  },
145
129
  }
146
130
  })
package/src/types.ts CHANGED
@@ -1,32 +1,13 @@
1
- import type { Plugin, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
2
- import type * as KubbFile from '@kubb/fs/types'
1
+ import type { Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
3
2
 
4
3
  import type { SchemaObject } from '@kubb/oas'
5
- import type { Exclude, Include, Override, ResolvePathOptions, Schema } from '@kubb/plugin-oas'
4
+ import type { Exclude, Generator, Include, Override, ResolvePathOptions, Schema } from '@kubb/plugin-oas'
6
5
 
7
6
  export 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
-
7
+ /**
8
+ * @default 'handlers'
9
+ */
10
+ output?: Output
30
11
  /**
31
12
  * Group the Faker mocks based on the provided name.
32
13
  */
@@ -74,26 +55,14 @@ export type Options = {
74
55
  * - Schema with format 'time' will use ISO time format (HH:mm:ss[.SSSSSS])
75
56
  * - `'dayjs'` will use `dayjs(faker.date.anytime()).format("HH:mm:ss")`.
76
57
  * - `undefined` will use `faker.date.anytime().toString()`
77
- * * @default undefined
58
+ * * @default 'faker'
78
59
  */
79
- dateParser?: 'dayjs' | 'moment' | (string & {})
60
+ dateParser?: 'faker' | 'dayjs' | 'moment' | (string & {})
80
61
  /**
81
62
  * Which type to use when the Swagger/OpenAPI file is not providing more information
82
63
  * @default 'any'
83
64
  */
84
65
  unknownType?: 'any' | 'unknown'
85
- transformers?: {
86
- /**
87
- * Customize the names based on the type that is provided by the plugin.
88
- */
89
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
90
- /**
91
- * Receive schema and baseName(propertName) and return FakerMeta array
92
- * TODO TODO add docs
93
- * @beta
94
- */
95
- schema?: (props: { schema?: SchemaObject; name?: string; parentName?: string }, defaultSchemas: Schema[]) => Schema[] | undefined
96
- }
97
66
  /**
98
67
  * Choose which generator to use when using Regexp.
99
68
  *
@@ -108,23 +77,33 @@ export type Options = {
108
77
  * The use of Seed is intended to allow for consistent values in a test.
109
78
  */
110
79
  seed?: number | number[]
80
+ transformers?: {
81
+ /**
82
+ * Customize the names based on the type that is provided by the plugin.
83
+ */
84
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
85
+ /**
86
+ * Receive schema and baseName(propertName) and return FakerMeta array
87
+ * TODO TODO add docs
88
+ * @beta
89
+ */
90
+ schema?: (props: { schema?: SchemaObject; name?: string; parentName?: string }, defaultSchemas: Schema[]) => Schema[] | undefined
91
+ }
92
+ /**
93
+ * Define some generators next to the faker generators
94
+ */
95
+ generators?: Array<Generator<PluginFaker>>
111
96
  }
112
97
 
113
98
  type ResolvedOptions = {
114
- extName: KubbFile.Extname | undefined
99
+ output: Output
100
+ override: NonNullable<Options['override']>
115
101
  dateType: NonNullable<Options['dateType']>
116
- dateParser: Options['dateParser']
102
+ dateParser: NonNullable<Options['dateParser']>
117
103
  unknownType: NonNullable<Options['unknownType']>
118
104
  transformers: NonNullable<Options['transformers']>
119
- override: NonNullable<Options['override']>
120
105
  seed: NonNullable<Options['seed']> | undefined
121
106
  mapper: NonNullable<Options['mapper']>
122
107
  regexGenerator: NonNullable<Options['regexGenerator']>
123
108
  }
124
-
125
- export type FileMeta = {
126
- pluginKey?: Plugin['key']
127
- tag?: string
128
- }
129
-
130
109
  export type PluginFaker = PluginFactoryOptions<'plugin-faker', Options, ResolvedOptions, never, ResolvePathOptions>
@@ -1,31 +0,0 @@
1
- import { OperationGenerator as Generator } from '@kubb/plugin-oas'
2
- import { Oas } from '@kubb/plugin-oas/components'
3
- import { App, createRoot } from '@kubb/react'
4
-
5
- import { OperationSchema } from './components/OperationSchema.tsx'
6
-
7
- import type { Operation } from '@kubb/oas'
8
- import type { OperationMethodResult } from '@kubb/plugin-oas'
9
- import type { FileMeta, PluginFaker } from './types.ts'
10
-
11
- export class OperationGenerator extends Generator<PluginFaker['resolvedOptions'], PluginFaker> {
12
- async operation(operation: Operation, options: PluginFaker['resolvedOptions']): OperationMethodResult<FileMeta> {
13
- const { oas, pluginManager, plugin, mode } = this.context
14
-
15
- const root = createRoot({
16
- logger: pluginManager.logger,
17
- })
18
-
19
- root.render(
20
- <App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>
21
- <Oas oas={oas} operations={[operation]} generator={this}>
22
- <Oas.Operation operation={operation}>
23
- <OperationSchema.File />
24
- </Oas.Operation>
25
- </Oas>
26
- </App>,
27
- )
28
-
29
- return root.files
30
- }
31
- }
@@ -1,31 +0,0 @@
1
- import type { SchemaObject } from '@kubb/oas'
2
- import { SchemaGenerator as Generator } from '@kubb/plugin-oas'
3
- import type { SchemaMethodResult } from '@kubb/plugin-oas'
4
- import { Oas } from '@kubb/plugin-oas/components'
5
- import { App, createRoot } from '@kubb/react'
6
- import { Schema } from './components/Schema.tsx'
7
- import type { FileMeta, PluginFaker } from './types.ts'
8
-
9
- export class SchemaGenerator extends Generator<PluginFaker['resolvedOptions'], PluginFaker> {
10
- async schema(name: string, schema: SchemaObject, options: PluginFaker['resolvedOptions']): SchemaMethodResult<FileMeta> {
11
- const { oas, pluginManager, plugin, mode, output } = this.context
12
-
13
- const root = createRoot({
14
- logger: pluginManager.logger,
15
- })
16
-
17
- const tree = this.parse({ schema, name })
18
-
19
- root.render(
20
- <App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>
21
- <Oas oas={oas}>
22
- <Oas.Schema name={name} value={schema} tree={tree}>
23
- <Schema.File />
24
- </Oas.Schema>
25
- </Oas>
26
- </App>,
27
- )
28
-
29
- return root.files
30
- }
31
- }