@kubb/plugin-faker 3.0.0-alpha.2 → 3.0.0-alpha.20
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-4RI7I4U6.cjs +115 -0
- package/dist/chunk-4RI7I4U6.cjs.map +1 -0
- package/dist/chunk-ORCMQTO5.js +304 -0
- package/dist/chunk-ORCMQTO5.js.map +1 -0
- package/dist/chunk-RKYLMZMT.js +113 -0
- package/dist/chunk-RKYLMZMT.js.map +1 -0
- package/dist/chunk-XCZY3DPW.cjs +310 -0
- package/dist/chunk-XCZY3DPW.cjs.map +1 -0
- package/dist/components.cjs +6 -565
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +15 -18
- package/dist/components.d.ts +15 -18
- package/dist/components.js +2 -570
- 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 +8 -0
- package/dist/generators.d.ts +8 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +51 -504
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -125
- package/dist/index.d.ts +4 -125
- package/dist/index.js +34 -494
- package/dist/index.js.map +1 -1
- package/dist/types-dutOIgtG.d.cts +108 -0
- package/dist/types-dutOIgtG.d.ts +108 -0
- package/package.json +19 -15
- 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 +8 -0
- package/src/generators/__snapshots__/petWithDateString.ts +8 -0
- package/src/generators/__snapshots__/petWithDayjs.ts +9 -0
- package/src/generators/__snapshots__/petWithMapper.ts +8 -0
- package/src/generators/__snapshots__/petWithRandExp.ts +9 -0
- package/src/generators/__snapshots__/pets.ts +8 -0
- package/src/generators/__snapshots__/showPetById.ts +29 -0
- package/src/generators/fakerGenerator.tsx +140 -0
- package/src/generators/index.ts +1 -0
- package/src/parser/index.ts +23 -13
- package/src/plugin.ts +20 -33
- package/src/types.ts +22 -47
- package/src/OperationGenerator.tsx +0 -30
- package/src/SchemaGenerator.tsx +0 -31
- package/src/components/OperationSchema.tsx +0 -84
- package/src/components/Schema.tsx +0 -146
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { Oas } from '@kubb/plugin-oas/components'
|
|
2
|
-
import { File, Function, useApp, useFile } from '@kubb/react'
|
|
3
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
4
|
-
|
|
5
|
-
import transformers from '@kubb/core/transformers'
|
|
6
|
-
import { schemaKeywords } from '@kubb/plugin-oas'
|
|
7
|
-
import { useSchema } from '@kubb/plugin-oas/hooks'
|
|
8
|
-
import type { ReactNode } from 'react'
|
|
9
|
-
import * as parserFaker from '../parser/index.ts'
|
|
10
|
-
import { pluginFakerName } from '../plugin.ts'
|
|
11
|
-
import type { PluginFaker } from '../types.ts'
|
|
12
|
-
|
|
13
|
-
type Props = {
|
|
14
|
-
description?: string
|
|
15
|
-
withData?: boolean
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function Schema(props: Props): ReactNode {
|
|
19
|
-
const { withData, description } = props
|
|
20
|
-
const { tree, name } = useSchema()
|
|
21
|
-
const {
|
|
22
|
-
pluginManager,
|
|
23
|
-
plugin: {
|
|
24
|
-
options: { dateParser, regexGenerator, mapper, seed },
|
|
25
|
-
},
|
|
26
|
-
} = useApp<PluginFaker>()
|
|
27
|
-
|
|
28
|
-
// all checks are also inside this.schema(React)
|
|
29
|
-
const resolvedName = pluginManager.resolveName({
|
|
30
|
-
name,
|
|
31
|
-
pluginKey: [pluginFakerName],
|
|
32
|
-
type: 'function',
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
const typeName = pluginManager.resolveName({
|
|
36
|
-
name,
|
|
37
|
-
pluginKey: [pluginTsName],
|
|
38
|
-
type: 'type',
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
const fakerText = parserFaker.joinItems(
|
|
42
|
-
tree
|
|
43
|
-
.map((schema) => parserFaker.parse(undefined, schema, { name: resolvedName, typeName, seed, regexGenerator, mapper, withData, dateParser }))
|
|
44
|
-
.filter(Boolean),
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
let fakerDefaultOverride: '' | '[]' | '{}' | undefined = undefined
|
|
48
|
-
let fakerTextWithOverride = fakerText
|
|
49
|
-
|
|
50
|
-
if (withData && fakerText.startsWith('{')) {
|
|
51
|
-
fakerDefaultOverride = '{}'
|
|
52
|
-
fakerTextWithOverride = `{
|
|
53
|
-
...${fakerText},
|
|
54
|
-
...data
|
|
55
|
-
}`
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (withData && fakerText.startsWith('faker.helpers.arrayElements')) {
|
|
59
|
-
fakerDefaultOverride = '[]'
|
|
60
|
-
fakerTextWithOverride = `[
|
|
61
|
-
...${fakerText},
|
|
62
|
-
...data
|
|
63
|
-
]`
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const params = fakerDefaultOverride ? `data: NonNullable<Partial<${typeName}>> = ${fakerDefaultOverride}` : `data?: NonNullable<Partial<${typeName}>>`
|
|
67
|
-
|
|
68
|
-
return (
|
|
69
|
-
<>
|
|
70
|
-
<Function
|
|
71
|
-
export
|
|
72
|
-
name={resolvedName}
|
|
73
|
-
JSDoc={{ comments: [description ? `@description ${transformers.jsStringEscape(description)}` : undefined].filter(Boolean) }}
|
|
74
|
-
params={withData ? params : ''}
|
|
75
|
-
returnType={typeName ? `NonNullable<${typeName}>` : ''}
|
|
76
|
-
>
|
|
77
|
-
{seed ? `faker.seed(${JSON.stringify(seed)})` : ''}
|
|
78
|
-
<br />
|
|
79
|
-
<Function.Return>{fakerTextWithOverride}</Function.Return>
|
|
80
|
-
</Function>
|
|
81
|
-
<br />
|
|
82
|
-
</>
|
|
83
|
-
)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
type FileProps = {}
|
|
87
|
-
|
|
88
|
-
Schema.File = function ({}: FileProps): ReactNode {
|
|
89
|
-
const { pluginManager } = useApp<PluginFaker>()
|
|
90
|
-
const { tree, schema } = useSchema()
|
|
91
|
-
|
|
92
|
-
const withData = tree.some(
|
|
93
|
-
(schema) =>
|
|
94
|
-
schema.keyword === schemaKeywords.array ||
|
|
95
|
-
schema.keyword === schemaKeywords.and ||
|
|
96
|
-
schema.keyword === schemaKeywords.object ||
|
|
97
|
-
schema.keyword === schemaKeywords.union ||
|
|
98
|
-
schema.keyword === schemaKeywords.tuple,
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
return (
|
|
102
|
-
<Oas.Schema.File output={pluginManager.config.output.path}>
|
|
103
|
-
<Schema.Imports />
|
|
104
|
-
<File.Source>
|
|
105
|
-
<Schema description={schema?.description} withData={withData} />
|
|
106
|
-
</File.Source>
|
|
107
|
-
</Oas.Schema.File>
|
|
108
|
-
)
|
|
109
|
-
}
|
|
110
|
-
Schema.Imports = (): ReactNode => {
|
|
111
|
-
const {
|
|
112
|
-
pluginManager,
|
|
113
|
-
plugin: {
|
|
114
|
-
options: { extName, dateParser, regexGenerator },
|
|
115
|
-
},
|
|
116
|
-
} = useApp<PluginFaker>()
|
|
117
|
-
const { path: root } = useFile()
|
|
118
|
-
const { name, tree, schema } = useSchema()
|
|
119
|
-
|
|
120
|
-
// used for this.options.typed
|
|
121
|
-
const typeName = pluginManager.resolveName({
|
|
122
|
-
name,
|
|
123
|
-
pluginKey: [pluginTsName],
|
|
124
|
-
type: 'type',
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
const typeFileName = pluginManager.resolveName({
|
|
128
|
-
name: name,
|
|
129
|
-
pluginKey: [pluginTsName],
|
|
130
|
-
type: 'file',
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
const typePath = pluginManager.resolvePath({
|
|
134
|
-
baseName: typeFileName,
|
|
135
|
-
pluginKey: [pluginTsName],
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
return (
|
|
139
|
-
<>
|
|
140
|
-
<File.Import name={['faker']} path="@faker-js/faker" />
|
|
141
|
-
{regexGenerator === 'randexp' && <File.Import name={'RandExp'} path={'randexp'} />}
|
|
142
|
-
{dateParser && <File.Import path={dateParser} name={dateParser} />}
|
|
143
|
-
{typeName && typePath && <File.Import extName={extName} isTypeOnly root={root} path={typePath} name={[typeName]} />}
|
|
144
|
-
</>
|
|
145
|
-
)
|
|
146
|
-
}
|