@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.
@@ -3,7 +3,7 @@ import {
3
3
  Operations,
4
4
  Schema,
5
5
  init_esm_shims
6
- } from "./chunk-VSAW3SUC.js";
6
+ } from "./chunk-CUPQVLRZ.js";
7
7
 
8
8
  // src/components/index.ts
9
9
  init_esm_shims();
package/dist/index.cjs CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkPXJ5ZGKWcjs = require('./chunk-PXJ5ZGKW.cjs');
5
+ var _chunk57AHBVYKcjs = require('./chunk-57AHBVYK.cjs');
6
6
 
7
7
  // src/index.ts
8
- _chunkPXJ5ZGKWcjs.init_cjs_shims.call(void 0, );
8
+ _chunk57AHBVYKcjs.init_cjs_shims.call(void 0, );
9
9
 
10
10
 
11
11
 
12
- exports.pluginZod = _chunkPXJ5ZGKWcjs.pluginZod; exports.pluginZodName = _chunkPXJ5ZGKWcjs.pluginZodName;
12
+ exports.pluginZod = _chunk57AHBVYKcjs.pluginZod; exports.pluginZodName = _chunk57AHBVYKcjs.pluginZodName;
13
13
  //# sourceMappingURL=index.cjs.map
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  init_esm_shims,
3
3
  pluginZod,
4
4
  pluginZodName
5
- } from "./chunk-VSAW3SUC.js";
5
+ } from "./chunk-CUPQVLRZ.js";
6
6
 
7
7
  // src/index.ts
8
8
  init_esm_shims();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-zod",
3
- "version": "3.0.0-alpha.7",
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.7",
60
- "@kubb/fs": "3.0.0-alpha.7",
61
- "@kubb/oas": "3.0.0-alpha.7",
62
- "@kubb/parser-ts": "3.0.0-alpha.7",
63
- "@kubb/plugin-oas": "3.0.0-alpha.7",
64
- "@kubb/react": "3.0.0-alpha.7",
65
- "@kubb/types": "3.0.0-alpha.7"
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.7",
73
- "@kubb/config-ts": "3.0.0-alpha.7",
74
- "@kubb/config-tsup": "3.0.0-alpha.7"
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.7"
77
+ "@kubb/react": "3.0.0-alpha.9"
78
78
  },
79
79
  "engines": {
80
80
  "node": ">=20"
@@ -1,10 +1,10 @@
1
- import { createReactParser } from '@kubb/plugin-oas'
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 = createReactParser<PluginZod>({
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(([_key, { data, operation }], index) => {
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={index} name={names} root={file.path} path={getFile(operation).path} />
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>
@@ -12,7 +12,11 @@ export const zodKeywordMapper = {
12
12
  .join('')
13
13
  },
14
14
  integer: (coercion?: boolean, min?: number, max?: number) => {
15
- return [coercion ? 'z.coerce.number()' : 'z.number()', min !== undefined ? `.min(${min})` : undefined, max !== undefined ? `.max(${max})` : undefined]
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) || isKeyword(current, schemaKeywords.integer)) {
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
  }