@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
|
@@ -2225,9 +2225,9 @@ var _hooks = require('@kubb/plugin-oas/hooks');
|
|
|
2225
2225
|
var _jsxruntime = require('@kubb/react/jsx-runtime');
|
|
2226
2226
|
function Template({ name, typeName, api }) {
|
|
2227
2227
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
2228
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name, isExportable: true, children: `export const ${name} = ${JSON.stringify(api, void 0, 2)} as const` }),
|
|
2228
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name, isExportable: true, isIndexable: true, children: `export const ${name} = ${JSON.stringify(api, void 0, 2)} as const` }),
|
|
2229
2229
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "br", {}),
|
|
2230
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: typeName, isExportable: true, isTypeOnly: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Type, { name: typeName, export: true, children: `Infer<typeof ${name}>` }) })
|
|
2230
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: typeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Type, { name: typeName, export: true, children: `Infer<typeof ${name}>` }) })
|
|
2231
2231
|
] });
|
|
2232
2232
|
}
|
|
2233
2233
|
var defaultTemplates = { default: Template };
|
|
@@ -2565,10 +2565,10 @@ function Schema(props) {
|
|
|
2565
2565
|
);
|
|
2566
2566
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, import_react3.Fragment, { children: [
|
|
2567
2567
|
enums.map(({ name: name2, nameNode, typeName: typeName2, typeNode }, index) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, import_react3.Fragment, { children: [
|
|
2568
|
-
nameNode && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: name2, isExportable: true, children: _parserts.print.call(void 0, nameNode) }),
|
|
2569
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: typeName2, isExportable: ["enum", "asConst", "constEnum", "literal", void 0].includes(enumType), isTypeOnly: true, children: _parserts.print.call(void 0, typeNode) })
|
|
2568
|
+
nameNode && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: name2, isExportable: true, isIndexable: true, children: _parserts.print.call(void 0, nameNode) }),
|
|
2569
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: typeName2, isIndexable: true, isExportable: ["enum", "asConst", "constEnum", "literal", void 0].includes(enumType), isTypeOnly: true, children: _parserts.print.call(void 0, typeNode) })
|
|
2570
2570
|
] }, [name2, nameNode].join("-"))),
|
|
2571
|
-
enums.every((item) => item.typeName !== resolvedName) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: typeName, isTypeOnly: true, isExportable: true, children: _parserts.print.call(void 0, typeNodes) })
|
|
2571
|
+
enums.every((item) => item.typeName !== resolvedName) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: typeName, isTypeOnly: true, isExportable: true, isIndexable: true, children: _parserts.print.call(void 0, typeNodes) })
|
|
2572
2572
|
] });
|
|
2573
2573
|
}
|
|
2574
2574
|
Schema.File = function({}) {
|
|
@@ -2701,7 +2701,7 @@ OperationSchema.File = function({}) {
|
|
|
2701
2701
|
const combinedSchemaName = operation.method === "get" ? `${factoryName}Query` : `${factoryName}Mutation`;
|
|
2702
2702
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
2703
2703
|
items.map(mapItem),
|
|
2704
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: combinedSchemaName, isExportable: true, isTypeOnly: true, children: printCombinedSchema({ name: combinedSchemaName, operation, schemas, pluginManager }) })
|
|
2704
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: combinedSchemaName, isExportable: true, isIndexable: true, isTypeOnly: true, children: printCombinedSchema({ name: combinedSchemaName, operation, schemas, pluginManager }) })
|
|
2705
2705
|
] });
|
|
2706
2706
|
};
|
|
2707
2707
|
|
|
@@ -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 [
|
|
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 (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.string)) {
|
|
3071
3075
|
return zodKeywordMapper.string(options.coercion);
|
|
3072
3076
|
}
|
|
3073
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.number)
|
|
3077
|
+
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.number)) {
|
|
3074
3078
|
return zodKeywordMapper.number(options.coercion);
|
|
3075
3079
|
}
|
|
3080
|
+
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.integer)) {
|
|
3081
|
+
return zodKeywordMapper.integer(options.coercion);
|
|
3082
|
+
}
|
|
3076
3083
|
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.min)) {
|
|
3077
3084
|
return zodKeywordMapper.min(current.args);
|
|
3078
3085
|
}
|
|
@@ -3110,6 +3117,46 @@ init_cjs_shims();
|
|
|
3110
3117
|
init_cjs_shims();
|
|
3111
3118
|
|
|
3112
3119
|
|
|
3120
|
+
// src/components/OperationSchema.tsx
|
|
3121
|
+
init_cjs_shims();
|
|
3122
|
+
|
|
3123
|
+
|
|
3124
|
+
|
|
3125
|
+
|
|
3126
|
+
|
|
3127
|
+
function OperationSchema2({ description, keysToOmit }) {
|
|
3128
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema2, { keysToOmit, withTypeAnnotation: false, description });
|
|
3129
|
+
}
|
|
3130
|
+
OperationSchema2.File = function({}) {
|
|
3131
|
+
const { pluginManager, plugin, mode } = _react.useApp.call(void 0, );
|
|
3132
|
+
const { getSchemas, getFile } = _hooks.useOperationManager.call(void 0, );
|
|
3133
|
+
const oas = _hooks.useOas.call(void 0, );
|
|
3134
|
+
const operation = _hooks.useOperation.call(void 0, );
|
|
3135
|
+
const file = getFile(operation);
|
|
3136
|
+
const schemas = getSchemas(operation);
|
|
3137
|
+
const generator = new (0, _pluginoas.SchemaGenerator)(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(_optionalChain([schema, 'optionalAccess', _59 => _59.required])) ? !!schema.required.length : !!_optionalChain([schema, 'optionalAccess', _60 => _60.required]);
|
|
3147
|
+
const optional = !required && !!name.includes("Params");
|
|
3148
|
+
const tree = generator.parse({ schema, name });
|
|
3149
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _components.Oas.Schema, { name, value: schema, tree: [...tree, optional ? { keyword: _pluginoas.schemaKeywords.optional } : void 0].filter(Boolean), children: [
|
|
3150
|
+
mode === "split" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema.Imports, { isTypeOnly: false }),
|
|
3151
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, OperationSchema2, { description, keysToOmit })
|
|
3152
|
+
] }, i);
|
|
3153
|
+
};
|
|
3154
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
3155
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["z"], path: plugin.options.importPath }),
|
|
3156
|
+
items.map(mapItem)
|
|
3157
|
+
] });
|
|
3158
|
+
};
|
|
3159
|
+
|
|
3113
3160
|
// src/components/Operations.tsx
|
|
3114
3161
|
init_cjs_shims();
|
|
3115
3162
|
|
|
@@ -3137,8 +3184,8 @@ function Template2({ operationsName, pathsName, operations }) {
|
|
|
3137
3184
|
{}
|
|
3138
3185
|
);
|
|
3139
3186
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
3140
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: operationsName, isExportable: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Const, { export: true, name: operationsName, asConst: true, children: `{${_transformers2.default.stringifyObject(operationsJSON)}}` }) }),
|
|
3141
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: pathsName, isExportable: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Const, { export: true, name: pathsName, asConst: true, children: `{${_transformers2.default.stringifyObject(pathsJSON)}}` }) })
|
|
3187
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: operationsName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Const, { export: true, name: operationsName, asConst: true, children: `{${_transformers2.default.stringifyObject(operationsJSON)}}` }) }),
|
|
3188
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: pathsName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Const, { export: true, name: pathsName, asConst: true, children: `{${_transformers2.default.stringifyObject(pathsJSON)}}` }) })
|
|
3142
3189
|
] });
|
|
3143
3190
|
}
|
|
3144
3191
|
function RootTemplate({ children }) {
|
|
@@ -3155,9 +3202,9 @@ function RootTemplate({ children }) {
|
|
|
3155
3202
|
const { groupSchemasByName } = _hooks.useOperationManager.call(void 0, );
|
|
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(([
|
|
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__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: names, root: file.path, path: getFile(operation).path },
|
|
3207
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: names, root: file.path, path: getFile(operation).path }, key);
|
|
3161
3208
|
}).filter(Boolean);
|
|
3162
3209
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
3163
3210
|
mode === "split" && imports,
|
|
@@ -3177,49 +3224,9 @@ Operations.File = function(props) {
|
|
|
3177
3224
|
};
|
|
3178
3225
|
Operations.templates = defaultTemplates2;
|
|
3179
3226
|
|
|
3180
|
-
// src/components/OperationSchema.tsx
|
|
3181
|
-
init_cjs_shims();
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
function OperationSchema2({ description, keysToOmit }) {
|
|
3188
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema2, { keysToOmit, withTypeAnnotation: false, description });
|
|
3189
|
-
}
|
|
3190
|
-
OperationSchema2.File = function({}) {
|
|
3191
|
-
const { pluginManager, plugin, mode } = _react.useApp.call(void 0, );
|
|
3192
|
-
const { getSchemas, getFile } = _hooks.useOperationManager.call(void 0, );
|
|
3193
|
-
const oas = _hooks.useOas.call(void 0, );
|
|
3194
|
-
const operation = _hooks.useOperation.call(void 0, );
|
|
3195
|
-
const file = getFile(operation);
|
|
3196
|
-
const schemas = getSchemas(operation);
|
|
3197
|
-
const generator = new (0, _pluginoas.SchemaGenerator)(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(_optionalChain([schema, 'optionalAccess', _59 => _59.required])) ? !!schema.required.length : !!_optionalChain([schema, 'optionalAccess', _60 => _60.required]);
|
|
3207
|
-
const optional = !required && !!name.includes("Params");
|
|
3208
|
-
const tree = generator.parse({ schema, name });
|
|
3209
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _components.Oas.Schema, { name, value: schema, tree: [...tree, optional ? { keyword: _pluginoas.schemaKeywords.optional } : void 0].filter(Boolean), children: [
|
|
3210
|
-
mode === "split" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema.Imports, { isTypeOnly: false }),
|
|
3211
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, OperationSchema2, { description, keysToOmit })
|
|
3212
|
-
] }, i);
|
|
3213
|
-
};
|
|
3214
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
3215
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["z"], path: plugin.options.importPath }),
|
|
3216
|
-
items.map(mapItem)
|
|
3217
|
-
] });
|
|
3218
|
-
};
|
|
3219
|
-
|
|
3220
3227
|
// src/SchemaGenerator.tsx
|
|
3221
3228
|
|
|
3222
|
-
var zodParser = _pluginoas.
|
|
3229
|
+
var zodParser = _pluginoas.createReactGenerator.call(void 0, {
|
|
3223
3230
|
name: "plugin-zod",
|
|
3224
3231
|
Operations({ options }) {
|
|
3225
3232
|
if (!options.templates.operations) {
|
|
@@ -3377,7 +3384,7 @@ function Schema2(props) {
|
|
|
3377
3384
|
type: "type"
|
|
3378
3385
|
});
|
|
3379
3386
|
if (!tree.length) {
|
|
3380
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: resolvedName, isExportable: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
3387
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: resolvedName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
3381
3388
|
_react.Const,
|
|
3382
3389
|
{
|
|
3383
3390
|
name: resolvedName,
|
|
@@ -3398,7 +3405,7 @@ function Schema2(props) {
|
|
|
3398
3405
|
}).map((item) => parse2(void 0, item, { name, typeName, description, mapper, coercion, keysToOmit })).filter(Boolean).join("");
|
|
3399
3406
|
const suffix = output.endsWith(".nullable()") ? ".unwrap().and" : ".and";
|
|
3400
3407
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
3401
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: resolvedName, isExportable: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
3408
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: resolvedName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
3402
3409
|
_react.Const,
|
|
3403
3410
|
{
|
|
3404
3411
|
export: true,
|
|
@@ -3413,7 +3420,7 @@ function Schema2(props) {
|
|
|
3413
3420
|
].filter(Boolean).join("") || ""
|
|
3414
3421
|
}
|
|
3415
3422
|
) }),
|
|
3416
|
-
typedSchema && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: resolvedTypeName, isExportable: true, isTypeOnly: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Type, { export: true, name: resolvedTypeName, children: `z.infer<typeof ${resolvedName}>` }) })
|
|
3423
|
+
typedSchema && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: resolvedTypeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Type, { export: true, name: resolvedTypeName, children: `z.infer<typeof ${resolvedName}>` }) })
|
|
3417
3424
|
] });
|
|
3418
3425
|
}
|
|
3419
3426
|
Schema2.File = function({}) {
|
|
@@ -3467,7 +3474,7 @@ Schema2.Imports = () => {
|
|
|
3467
3474
|
|
|
3468
3475
|
|
|
3469
3476
|
|
|
3470
|
-
exports.init_cjs_shims = init_cjs_shims; exports.Schema = Schema2; exports.
|
|
3477
|
+
exports.init_cjs_shims = init_cjs_shims; exports.Schema = Schema2; exports.OperationSchema = OperationSchema2; exports.Operations = Operations; exports.pluginZodName = pluginZodName; exports.pluginZod = pluginZod;
|
|
3471
3478
|
/*! Bundled license information:
|
|
3472
3479
|
|
|
3473
3480
|
react/cjs/react.production.min.js:
|
|
@@ -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-
|
|
3502
|
+
//# sourceMappingURL=chunk-57AHBVYK.cjs.map
|