@kubb/plugin-zod 3.0.0-alpha.7 → 3.0.0-alpha.9
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-PXJ5ZGKW.cjs → chunk-57AHBVYK.cjs} +65 -58
- package/dist/chunk-57AHBVYK.cjs.map +1 -0
- package/dist/{chunk-VSAW3SUC.js → chunk-CUPQVLRZ.js} +77 -70
- package/dist/chunk-CUPQVLRZ.js.map +1 -0
- package/dist/components.cjs +3 -3
- package/dist/components.js +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.js +1 -1
- package/package.json +12 -12
- package/src/SchemaGenerator.tsx +4 -4
- package/src/components/Operations.tsx +4 -4
- package/src/components/Schema.tsx +3 -3
- package/src/parser/index.ts +10 -2
- package/dist/chunk-PXJ5ZGKW.cjs.map +0 -1
- package/dist/chunk-VSAW3SUC.js.map +0 -1
package/dist/components.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunk57AHBVYKcjs = require('./chunk-57AHBVYK.cjs');
|
|
6
6
|
|
|
7
7
|
// src/index.ts
|
|
8
|
-
|
|
8
|
+
_chunk57AHBVYKcjs.init_cjs_shims.call(void 0, );
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
exports.pluginZod =
|
|
12
|
+
exports.pluginZod = _chunk57AHBVYKcjs.pluginZod; exports.pluginZodName = _chunk57AHBVYKcjs.pluginZodName;
|
|
13
13
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-zod",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.9",
|
|
4
4
|
"description": "Generator plugin-zod",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -56,25 +56,25 @@
|
|
|
56
56
|
"!/**/__tests__/**"
|
|
57
57
|
],
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@kubb/core": "3.0.0-alpha.
|
|
60
|
-
"@kubb/fs": "3.0.0-alpha.
|
|
61
|
-
"@kubb/oas": "3.0.0-alpha.
|
|
62
|
-
"@kubb/parser-ts": "3.0.0-alpha.
|
|
63
|
-
"@kubb/plugin-oas": "3.0.0-alpha.
|
|
64
|
-
"@kubb/react": "3.0.0-alpha.
|
|
65
|
-
"@kubb/types": "3.0.0-alpha.
|
|
59
|
+
"@kubb/core": "3.0.0-alpha.9",
|
|
60
|
+
"@kubb/fs": "3.0.0-alpha.9",
|
|
61
|
+
"@kubb/oas": "3.0.0-alpha.9",
|
|
62
|
+
"@kubb/parser-ts": "3.0.0-alpha.9",
|
|
63
|
+
"@kubb/plugin-oas": "3.0.0-alpha.9",
|
|
64
|
+
"@kubb/react": "3.0.0-alpha.9",
|
|
65
|
+
"@kubb/types": "3.0.0-alpha.9"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@types/react": "^18.3.4",
|
|
69
69
|
"prettier": "^3.3.3",
|
|
70
70
|
"react": "^18.3.1",
|
|
71
71
|
"tsup": "^8.2.4",
|
|
72
|
-
"@kubb/config-biome": "3.0.0-alpha.
|
|
73
|
-
"@kubb/config-ts": "3.0.0-alpha.
|
|
74
|
-
"@kubb/config-tsup": "3.0.0-alpha.
|
|
72
|
+
"@kubb/config-biome": "3.0.0-alpha.9",
|
|
73
|
+
"@kubb/config-ts": "3.0.0-alpha.9",
|
|
74
|
+
"@kubb/config-tsup": "3.0.0-alpha.9"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"@kubb/react": "3.0.0-alpha.
|
|
77
|
+
"@kubb/react": "3.0.0-alpha.9"
|
|
78
78
|
},
|
|
79
79
|
"engines": {
|
|
80
80
|
"node": ">=20"
|
package/src/SchemaGenerator.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createReactGenerator } from '@kubb/plugin-oas'
|
|
2
|
+
import { OperationSchema } from './components/OperationSchema.tsx'
|
|
3
|
+
import { Operations } from './components/Operations.tsx'
|
|
2
4
|
import { Schema } from './components/Schema.tsx'
|
|
3
5
|
import type { PluginZod } from './types.ts'
|
|
4
|
-
import { Operations } from './components/Operations.tsx'
|
|
5
|
-
import { OperationSchema } from './components/OperationSchema.tsx'
|
|
6
6
|
|
|
7
|
-
export const zodParser =
|
|
7
|
+
export const zodParser = createReactGenerator<PluginZod>({
|
|
8
8
|
name: 'plugin-zod',
|
|
9
9
|
Operations({ options }) {
|
|
10
10
|
if (!options.templates.operations) {
|
|
@@ -46,12 +46,12 @@ function Template({ operationsName, pathsName, operations }: TemplateProps): Kub
|
|
|
46
46
|
|
|
47
47
|
return (
|
|
48
48
|
<>
|
|
49
|
-
<File.Source name={operationsName} isExportable>
|
|
49
|
+
<File.Source name={operationsName} isExportable isIndexable>
|
|
50
50
|
<Const export name={operationsName} asConst>
|
|
51
51
|
{`{${transformers.stringifyObject(operationsJSON)}}`}
|
|
52
52
|
</Const>
|
|
53
53
|
</File.Source>
|
|
54
|
-
<File.Source name={pathsName} isExportable>
|
|
54
|
+
<File.Source name={pathsName} isExportable isIndexable>
|
|
55
55
|
<Const export name={pathsName} asConst>
|
|
56
56
|
{`{${transformers.stringifyObject(pathsJSON)}}`}
|
|
57
57
|
</Const>
|
|
@@ -80,10 +80,10 @@ function RootTemplate({ children }: RootTemplateProps) {
|
|
|
80
80
|
|
|
81
81
|
const file = pluginManager.getFile({ name: 'operations', extName: '.ts', pluginKey })
|
|
82
82
|
const imports = Object.entries(transformedOperations)
|
|
83
|
-
.map(([
|
|
83
|
+
.map(([key, { data, operation }]) => {
|
|
84
84
|
const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)
|
|
85
85
|
|
|
86
|
-
return <File.Import key={
|
|
86
|
+
return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />
|
|
87
87
|
})
|
|
88
88
|
.filter(Boolean)
|
|
89
89
|
|
|
@@ -46,7 +46,7 @@ export function Schema(props: Props): ReactNode {
|
|
|
46
46
|
|
|
47
47
|
if (!tree.length) {
|
|
48
48
|
return (
|
|
49
|
-
<File.Source name={resolvedName} isExportable>
|
|
49
|
+
<File.Source name={resolvedName} isExportable isIndexable>
|
|
50
50
|
<Const
|
|
51
51
|
name={resolvedName}
|
|
52
52
|
export
|
|
@@ -79,7 +79,7 @@ export function Schema(props: Props): ReactNode {
|
|
|
79
79
|
|
|
80
80
|
return (
|
|
81
81
|
<>
|
|
82
|
-
<File.Source name={resolvedName} isExportable>
|
|
82
|
+
<File.Source name={resolvedName} isExportable isIndexable>
|
|
83
83
|
<Const
|
|
84
84
|
export
|
|
85
85
|
name={resolvedName}
|
|
@@ -97,7 +97,7 @@ export function Schema(props: Props): ReactNode {
|
|
|
97
97
|
</Const>
|
|
98
98
|
</File.Source>
|
|
99
99
|
{typedSchema && (
|
|
100
|
-
<File.Source name={resolvedTypeName} isExportable isTypeOnly>
|
|
100
|
+
<File.Source name={resolvedTypeName} isExportable isIndexable isTypeOnly>
|
|
101
101
|
<Type export name={resolvedTypeName}>
|
|
102
102
|
{`z.infer<typeof ${resolvedName}>`}
|
|
103
103
|
</Type>
|
package/src/parser/index.ts
CHANGED
|
@@ -12,7 +12,11 @@ export const zodKeywordMapper = {
|
|
|
12
12
|
.join('')
|
|
13
13
|
},
|
|
14
14
|
integer: (coercion?: boolean, min?: number, max?: number) => {
|
|
15
|
-
return [
|
|
15
|
+
return [
|
|
16
|
+
coercion ? 'z.coerce.number().int()' : 'z.number().int()',
|
|
17
|
+
min !== undefined ? `.min(${min})` : undefined,
|
|
18
|
+
max !== undefined ? `.max(${max})` : undefined,
|
|
19
|
+
]
|
|
16
20
|
.filter(Boolean)
|
|
17
21
|
.join('')
|
|
18
22
|
},
|
|
@@ -308,10 +312,14 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
|
|
|
308
312
|
return zodKeywordMapper.string(options.coercion)
|
|
309
313
|
}
|
|
310
314
|
|
|
311
|
-
if (isKeyword(current, schemaKeywords.number)
|
|
315
|
+
if (isKeyword(current, schemaKeywords.number)) {
|
|
312
316
|
return zodKeywordMapper.number(options.coercion)
|
|
313
317
|
}
|
|
314
318
|
|
|
319
|
+
if (isKeyword(current, schemaKeywords.integer)) {
|
|
320
|
+
return zodKeywordMapper.integer(options.coercion)
|
|
321
|
+
}
|
|
322
|
+
|
|
315
323
|
if (isKeyword(current, schemaKeywords.min)) {
|
|
316
324
|
return zodKeywordMapper.min(current.args)
|
|
317
325
|
}
|