@kubb/plugin-zod 3.0.0-alpha.8 → 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.
@@ -2850,7 +2850,11 @@ var zodKeywordMapper = {
2850
2850
  return [coercion ? "z.coerce.number()" : "z.number()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
2851
2851
  },
2852
2852
  integer: (coercion, min, max) => {
2853
- return [coercion ? "z.coerce.number()" : "z.number()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
2853
+ return [
2854
+ coercion ? "z.coerce.number().int()" : "z.number().int()",
2855
+ min !== void 0 ? `.min(${min})` : void 0,
2856
+ max !== void 0 ? `.max(${max})` : void 0
2857
+ ].filter(Boolean).join("");
2854
2858
  },
2855
2859
  object: (value) => `z.object({${value}})`,
2856
2860
  string: (coercion, min, max) => {
@@ -3070,9 +3074,12 @@ function parse2(parent, current, options) {
3070
3074
  if (isKeyword2(current, schemaKeywords3.string)) {
3071
3075
  return zodKeywordMapper.string(options.coercion);
3072
3076
  }
3073
- if (isKeyword2(current, schemaKeywords3.number) || isKeyword2(current, schemaKeywords3.integer)) {
3077
+ if (isKeyword2(current, schemaKeywords3.number)) {
3074
3078
  return zodKeywordMapper.number(options.coercion);
3075
3079
  }
3080
+ if (isKeyword2(current, schemaKeywords3.integer)) {
3081
+ return zodKeywordMapper.integer(options.coercion);
3082
+ }
3076
3083
  if (isKeyword2(current, schemaKeywords3.min)) {
3077
3084
  return zodKeywordMapper.min(current.args);
3078
3085
  }
@@ -3108,16 +3115,56 @@ import { OperationGenerator as OperationGenerator2, SchemaGenerator as SchemaGen
3108
3115
 
3109
3116
  // src/SchemaGenerator.tsx
3110
3117
  init_esm_shims();
3111
- import { createReactParser } from "@kubb/plugin-oas";
3118
+ import { createReactGenerator } from "@kubb/plugin-oas";
3119
+
3120
+ // src/components/OperationSchema.tsx
3121
+ init_esm_shims();
3122
+ import { SchemaGenerator as SchemaGenerator3, schemaKeywords as schemaKeywords4 } from "@kubb/plugin-oas";
3123
+ import { Oas as Oas5 } from "@kubb/plugin-oas/components";
3124
+ import { useOas as useOas3, useOperation as useOperation2, useOperationManager as useOperationManager2 } from "@kubb/plugin-oas/hooks";
3125
+ import { File as File4, useApp as useApp4 } from "@kubb/react";
3126
+ import { jsx as jsx6, jsxs as jsxs4 } from "@kubb/react/jsx-runtime";
3127
+ function OperationSchema2({ description, keysToOmit }) {
3128
+ return /* @__PURE__ */ jsx6(Schema2, { keysToOmit, withTypeAnnotation: false, description });
3129
+ }
3130
+ OperationSchema2.File = function({}) {
3131
+ const { pluginManager, plugin, mode } = useApp4();
3132
+ const { getSchemas, getFile } = useOperationManager2();
3133
+ const oas = useOas3();
3134
+ const operation = useOperation2();
3135
+ const file = getFile(operation);
3136
+ const schemas = getSchemas(operation);
3137
+ const generator = new SchemaGenerator3(plugin.options, {
3138
+ oas,
3139
+ plugin,
3140
+ pluginManager,
3141
+ mode,
3142
+ override: plugin.options.override
3143
+ });
3144
+ const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
3145
+ const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
3146
+ const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required;
3147
+ const optional = !required && !!name.includes("Params");
3148
+ const tree = generator.parse({ schema, name });
3149
+ return /* @__PURE__ */ jsxs4(Oas5.Schema, { name, value: schema, tree: [...tree, optional ? { keyword: schemaKeywords4.optional } : void 0].filter(Boolean), children: [
3150
+ mode === "split" && /* @__PURE__ */ jsx6(Oas5.Schema.Imports, { isTypeOnly: false }),
3151
+ /* @__PURE__ */ jsx6(OperationSchema2, { description, keysToOmit })
3152
+ ] }, i);
3153
+ };
3154
+ return /* @__PURE__ */ jsxs4(File4, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
3155
+ /* @__PURE__ */ jsx6(File4.Import, { name: ["z"], path: plugin.options.importPath }),
3156
+ items.map(mapItem)
3157
+ ] });
3158
+ };
3112
3159
 
3113
3160
  // src/components/Operations.tsx
3114
3161
  init_esm_shims();
3115
- import { useOperationManager as useOperationManager2, useOperations } from "@kubb/plugin-oas/hooks";
3116
- import { Const, File as File4, useApp as useApp4 } from "@kubb/react";
3162
+ import { useOperationManager as useOperationManager3, useOperations } from "@kubb/plugin-oas/hooks";
3163
+ import { Const, File as File5, useApp as useApp5 } from "@kubb/react";
3117
3164
  import transformers5 from "@kubb/core/transformers";
3118
- import { Fragment as Fragment3, jsx as jsx6, jsxs as jsxs4 } from "@kubb/react/jsx-runtime";
3165
+ import { Fragment as Fragment3, jsx as jsx7, jsxs as jsxs5 } from "@kubb/react/jsx-runtime";
3119
3166
  function Template2({ operationsName, pathsName, operations }) {
3120
- const { groupSchemasByName } = useOperationManager2();
3167
+ const { groupSchemasByName } = useOperationManager3();
3121
3168
  const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
3122
3169
  const operationsJSON = transformedOperations.reduce(
3123
3170
  (prev, acc) => {
@@ -3136,9 +3183,9 @@ function Template2({ operationsName, pathsName, operations }) {
3136
3183
  },
3137
3184
  {}
3138
3185
  );
3139
- return /* @__PURE__ */ jsxs4(Fragment3, { children: [
3140
- /* @__PURE__ */ jsx6(File4.Source, { name: operationsName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx6(Const, { export: true, name: operationsName, asConst: true, children: `{${transformers5.stringifyObject(operationsJSON)}}` }) }),
3141
- /* @__PURE__ */ jsx6(File4.Source, { name: pathsName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx6(Const, { export: true, name: pathsName, asConst: true, children: `{${transformers5.stringifyObject(pathsJSON)}}` }) })
3186
+ return /* @__PURE__ */ jsxs5(Fragment3, { children: [
3187
+ /* @__PURE__ */ jsx7(File5.Source, { name: operationsName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx7(Const, { export: true, name: operationsName, asConst: true, children: `{${transformers5.stringifyObject(operationsJSON)}}` }) }),
3188
+ /* @__PURE__ */ jsx7(File5.Source, { name: pathsName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx7(Const, { export: true, name: pathsName, asConst: true, children: `{${transformers5.stringifyObject(pathsJSON)}}` }) })
3142
3189
  ] });
3143
3190
  }
3144
3191
  function RootTemplate({ children }) {
@@ -3149,17 +3196,17 @@ function RootTemplate({ children }) {
3149
3196
  key: pluginKey,
3150
3197
  options: { extName }
3151
3198
  }
3152
- } = useApp4();
3153
- const { getFile } = useOperationManager2();
3199
+ } = useApp5();
3200
+ const { getFile } = useOperationManager3();
3154
3201
  const operations = useOperations();
3155
- const { groupSchemasByName } = useOperationManager2();
3202
+ const { groupSchemasByName } = useOperationManager3();
3156
3203
  const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
3157
3204
  const file = pluginManager.getFile({ name: "operations", extName: ".ts", pluginKey });
3158
- const imports = Object.entries(transformedOperations).map(([_key, { data, operation }], index) => {
3205
+ const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
3159
3206
  const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
3160
- return /* @__PURE__ */ jsx6(File4.Import, { name: names, root: file.path, path: getFile(operation).path }, index);
3207
+ return /* @__PURE__ */ jsx7(File5.Import, { name: names, root: file.path, path: getFile(operation).path }, key);
3161
3208
  }).filter(Boolean);
3162
- return /* @__PURE__ */ jsxs4(File4, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
3209
+ return /* @__PURE__ */ jsxs5(File5, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
3163
3210
  mode === "split" && imports,
3164
3211
  children
3165
3212
  ] });
@@ -3167,59 +3214,19 @@ function RootTemplate({ children }) {
3167
3214
  var defaultTemplates2 = { default: Template2, root: RootTemplate };
3168
3215
  function Operations({ Template: Template3 = defaultTemplates2.default }) {
3169
3216
  const operations = useOperations();
3170
- return /* @__PURE__ */ jsx6(Template3, { operationsName: "operations", pathsName: "paths", operations });
3217
+ return /* @__PURE__ */ jsx7(Template3, { operationsName: "operations", pathsName: "paths", operations });
3171
3218
  }
3172
3219
  Operations.File = function(props) {
3173
3220
  const templates = { ...defaultTemplates2, ...props.templates };
3174
3221
  const Template3 = templates.default;
3175
3222
  const RootTemplate2 = templates.root;
3176
- return /* @__PURE__ */ jsx6(RootTemplate2, { children: /* @__PURE__ */ jsx6(Operations, { Template: Template3 }) });
3223
+ return /* @__PURE__ */ jsx7(RootTemplate2, { children: /* @__PURE__ */ jsx7(Operations, { Template: Template3 }) });
3177
3224
  };
3178
3225
  Operations.templates = defaultTemplates2;
3179
3226
 
3180
- // src/components/OperationSchema.tsx
3181
- init_esm_shims();
3182
- import { SchemaGenerator as SchemaGenerator3, schemaKeywords as schemaKeywords4 } from "@kubb/plugin-oas";
3183
- import { Oas as Oas5 } from "@kubb/plugin-oas/components";
3184
- import { useOas as useOas3, useOperation as useOperation2, useOperationManager as useOperationManager3 } from "@kubb/plugin-oas/hooks";
3185
- import { File as File5, useApp as useApp5 } from "@kubb/react";
3186
- import { jsx as jsx7, jsxs as jsxs5 } from "@kubb/react/jsx-runtime";
3187
- function OperationSchema2({ description, keysToOmit }) {
3188
- return /* @__PURE__ */ jsx7(Schema2, { keysToOmit, withTypeAnnotation: false, description });
3189
- }
3190
- OperationSchema2.File = function({}) {
3191
- const { pluginManager, plugin, mode } = useApp5();
3192
- const { getSchemas, getFile } = useOperationManager3();
3193
- const oas = useOas3();
3194
- const operation = useOperation2();
3195
- const file = getFile(operation);
3196
- const schemas = getSchemas(operation);
3197
- const generator = new SchemaGenerator3(plugin.options, {
3198
- oas,
3199
- plugin,
3200
- pluginManager,
3201
- mode,
3202
- override: plugin.options.override
3203
- });
3204
- const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
3205
- const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
3206
- const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required;
3207
- const optional = !required && !!name.includes("Params");
3208
- const tree = generator.parse({ schema, name });
3209
- return /* @__PURE__ */ jsxs5(Oas5.Schema, { name, value: schema, tree: [...tree, optional ? { keyword: schemaKeywords4.optional } : void 0].filter(Boolean), children: [
3210
- mode === "split" && /* @__PURE__ */ jsx7(Oas5.Schema.Imports, { isTypeOnly: false }),
3211
- /* @__PURE__ */ jsx7(OperationSchema2, { description, keysToOmit })
3212
- ] }, i);
3213
- };
3214
- return /* @__PURE__ */ jsxs5(File5, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
3215
- /* @__PURE__ */ jsx7(File5.Import, { name: ["z"], path: plugin.options.importPath }),
3216
- items.map(mapItem)
3217
- ] });
3218
- };
3219
-
3220
3227
  // src/SchemaGenerator.tsx
3221
3228
  import { jsx as jsx8 } from "@kubb/react/jsx-runtime";
3222
- var zodParser = createReactParser({
3229
+ var zodParser = createReactGenerator({
3223
3230
  name: "plugin-zod",
3224
3231
  Operations({ options }) {
3225
3232
  if (!options.templates.operations) {
@@ -3463,8 +3470,8 @@ Schema2.Imports = () => {
3463
3470
  export {
3464
3471
  init_esm_shims,
3465
3472
  Schema2 as Schema,
3466
- Operations,
3467
3473
  OperationSchema2 as OperationSchema,
3474
+ Operations,
3468
3475
  pluginZodName,
3469
3476
  pluginZod
3470
3477
  };
@@ -3492,4 +3499,4 @@ react/cjs/react.development.js:
3492
3499
  * LICENSE file in the root directory of this source tree.
3493
3500
  *)
3494
3501
  */
3495
- //# sourceMappingURL=chunk-CD3EZWBX.js.map
3502
+ //# sourceMappingURL=chunk-CUPQVLRZ.js.map