@kubb/plugin-faker 3.0.0-alpha.4 → 3.0.0-alpha.6
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/components.cjs +15 -34
- package/dist/components.cjs.map +1 -1
- package/dist/components.js +15 -34
- package/dist/components.js.map +1 -1
- package/dist/index.cjs +14 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +15 -34
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
- package/src/components/OperationSchema.tsx +9 -13
- package/src/components/Schema.tsx +4 -6
- package/src/plugin.ts +7 -27
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Oas } from '@kubb/plugin-oas/components'
|
|
2
2
|
import { useOas, useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
3
|
-
import { File,
|
|
3
|
+
import { File, useApp } from '@kubb/react'
|
|
4
4
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
5
5
|
|
|
6
6
|
import { SchemaGenerator } from '../SchemaGenerator.tsx'
|
|
@@ -61,24 +61,20 @@ OperationSchema.File = function ({}: FileProps): ReactNode {
|
|
|
61
61
|
|
|
62
62
|
return (
|
|
63
63
|
<Oas.Schema key={i} name={name} value={schema} tree={tree}>
|
|
64
|
-
{typeName && typePath && <File.Import
|
|
64
|
+
{typeName && typePath && <File.Import isTypeOnly root={file.path} path={typePath} name={[typeName]} />}
|
|
65
65
|
{plugin.options.dateParser && <File.Import path={plugin.options.dateParser} name={plugin.options.dateParser} />}
|
|
66
66
|
|
|
67
|
-
{mode === 'split' && <Oas.Schema.Imports
|
|
68
|
-
<
|
|
69
|
-
<OperationSchema description={description} />
|
|
70
|
-
</File.Source>
|
|
67
|
+
{mode === 'split' && <Oas.Schema.Imports />}
|
|
68
|
+
<OperationSchema description={description} />
|
|
71
69
|
</Oas.Schema>
|
|
72
70
|
)
|
|
73
71
|
}
|
|
74
72
|
|
|
75
73
|
return (
|
|
76
|
-
<
|
|
77
|
-
<File
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
</File>
|
|
82
|
-
</Parser>
|
|
74
|
+
<File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
|
|
75
|
+
<File.Import name={['faker']} path="@faker-js/faker" />
|
|
76
|
+
{plugin.options.regexGenerator === 'randexp' && <File.Import name={'RandExp'} path={'randexp'} />}
|
|
77
|
+
{items.map(mapItem)}
|
|
78
|
+
</File>
|
|
83
79
|
)
|
|
84
80
|
}
|
|
@@ -66,7 +66,7 @@ export function Schema(props: Props): ReactNode {
|
|
|
66
66
|
const params = fakerDefaultOverride ? `data: NonNullable<Partial<${typeName}>> = ${fakerDefaultOverride}` : `data?: NonNullable<Partial<${typeName}>>`
|
|
67
67
|
|
|
68
68
|
return (
|
|
69
|
-
|
|
69
|
+
<File.Source name={resolvedName} isExportable>
|
|
70
70
|
<Function
|
|
71
71
|
export
|
|
72
72
|
name={resolvedName}
|
|
@@ -79,7 +79,7 @@ export function Schema(props: Props): ReactNode {
|
|
|
79
79
|
<Function.Return>{fakerTextWithOverride}</Function.Return>
|
|
80
80
|
</Function>
|
|
81
81
|
<br />
|
|
82
|
-
|
|
82
|
+
</File.Source>
|
|
83
83
|
)
|
|
84
84
|
}
|
|
85
85
|
|
|
@@ -101,9 +101,7 @@ Schema.File = function ({}: FileProps): ReactNode {
|
|
|
101
101
|
return (
|
|
102
102
|
<Oas.Schema.File output={pluginManager.config.output.path}>
|
|
103
103
|
<Schema.Imports />
|
|
104
|
-
<
|
|
105
|
-
<Schema description={schema?.description} withData={withData} />
|
|
106
|
-
</File.Source>
|
|
104
|
+
<Schema description={schema?.description} withData={withData} />
|
|
107
105
|
</Oas.Schema.File>
|
|
108
106
|
)
|
|
109
107
|
}
|
|
@@ -140,7 +138,7 @@ Schema.Imports = (): ReactNode => {
|
|
|
140
138
|
<File.Import name={['faker']} path="@faker-js/faker" />
|
|
141
139
|
{regexGenerator === 'randexp' && <File.Import name={'RandExp'} path={'randexp'} />}
|
|
142
140
|
{dateParser && <File.Import path={dateParser} name={dateParser} />}
|
|
143
|
-
{typeName && typePath && <File.Import
|
|
141
|
+
{typeName && typePath && <File.Import isTypeOnly root={root} path={typePath} name={[typeName]} />}
|
|
144
142
|
</>
|
|
145
143
|
)
|
|
146
144
|
}
|
package/src/plugin.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { FileManager, PluginManager, createPlugin } from '@kubb/core'
|
|
|
4
4
|
import { camelCase } from '@kubb/core/transformers'
|
|
5
5
|
import { renderTemplate } from '@kubb/core/utils'
|
|
6
6
|
import { pluginOasName } from '@kubb/plugin-oas'
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
9
9
|
|
|
10
10
|
import { OperationGenerator } from './OperationGenerator.tsx'
|
|
@@ -114,37 +114,17 @@ export const pluginFaker = createPlugin<PluginFaker>((options) => {
|
|
|
114
114
|
const operationFiles = await operationGenerator.build()
|
|
115
115
|
await this.addFile(...operationFiles)
|
|
116
116
|
|
|
117
|
-
if (this.config.output.write
|
|
118
|
-
const
|
|
119
|
-
logger: this.logger,
|
|
120
|
-
files: this.fileManager.files,
|
|
121
|
-
plugin: this.plugin,
|
|
122
|
-
template,
|
|
123
|
-
exportAs: group.exportAs || '{{tag}}Mocks',
|
|
117
|
+
if (this.config.output.write) {
|
|
118
|
+
const indexFiles = await this.fileManager.getIndexFiles({
|
|
124
119
|
root,
|
|
125
120
|
output,
|
|
121
|
+
files: this.fileManager.files,
|
|
122
|
+
plugin: this.plugin,
|
|
123
|
+
logger: this.logger,
|
|
126
124
|
})
|
|
127
125
|
|
|
128
|
-
await this.addFile(...
|
|
126
|
+
await this.addFile(...indexFiles)
|
|
129
127
|
}
|
|
130
128
|
},
|
|
131
|
-
async buildEnd() {
|
|
132
|
-
if (this.config.output.write === false) {
|
|
133
|
-
return
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const root = path.resolve(this.config.root, this.config.output.path)
|
|
137
|
-
const files = await this.fileManager.getIndexFiles({
|
|
138
|
-
root,
|
|
139
|
-
output,
|
|
140
|
-
meta: { pluginKey: this.plugin.key },
|
|
141
|
-
logger: this.logger,
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
await this.fileManager.processFiles({
|
|
145
|
-
logger: this.logger,
|
|
146
|
-
files,
|
|
147
|
-
})
|
|
148
|
-
},
|
|
149
129
|
}
|
|
150
130
|
})
|