@kubb/plugin-zod 5.4.4 → 5.4.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/OVERVIEW.md +20 -0
- package/dist/index.cjs +39 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +40 -31
- package/dist/index.js.map +1 -1
- package/kubb-extension.json +204 -0
- package/package.json +7 -4
package/OVERVIEW.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Zod
|
|
2
|
+
|
|
3
|
+
Generates Zod v4 schemas from your OpenAPI spec. Use them to validate API responses, form input, and query params at runtime.
|
|
4
|
+
|
|
5
|
+
The schemas can stand on their own. With `inferred: true`, the plugin also exports a `z.infer` type next to each schema, so you can skip `@kubb/plugin-ts`. Client plugins such as `@kubb/plugin-fetch` and `@kubb/plugin-axios` use these schemas when you set their `validator` option.
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
Install Zod v4 or higher in the app that uses the generated code. No other plugins are needed.
|
|
10
|
+
|
|
11
|
+
## Options worth knowing
|
|
12
|
+
|
|
13
|
+
- `mini` generates Zod Mini schemas for smaller bundles, and switches `importPath` to `zod/mini`.
|
|
14
|
+
- `importPath` sets the module the files import `z` from. The default is `zod`.
|
|
15
|
+
- `inferred` exports a `z.infer` type alias next to each schema.
|
|
16
|
+
- `coercion` wraps schemas in `z.coerce`, so input is converted before validation. Pass an object to coerce only dates, strings, or numbers.
|
|
17
|
+
- `guidType` picks `z.uuid()` (default) or `z.guid()` for `format: uuid`.
|
|
18
|
+
- `regexType` writes a `pattern` as a regex literal (default) or a `RegExp` constructor.
|
|
19
|
+
- `typeGuards` adds `is*` type guards and `assert*` assertions.
|
|
20
|
+
- `compile` wraps schemas in `z.compile` for faster validation.
|
package/dist/index.cjs
CHANGED
|
@@ -2229,6 +2229,15 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2229
2229
|
}
|
|
2230
2230
|
});
|
|
2231
2231
|
//#endregion
|
|
2232
|
+
//#region kubb-extension.json
|
|
2233
|
+
var compatibility = {
|
|
2234
|
+
"kubb": ">=5.8.0",
|
|
2235
|
+
"node": ">=22"
|
|
2236
|
+
};
|
|
2237
|
+
//#endregion
|
|
2238
|
+
//#region package.json
|
|
2239
|
+
var version = "5.4.6";
|
|
2240
|
+
//#endregion
|
|
2232
2241
|
//#region src/resolvers/resolverZod.ts
|
|
2233
2242
|
/**
|
|
2234
2243
|
* Default resolver used by `@kubb/plugin-zod`. Decides the names and file
|
|
@@ -2315,37 +2324,37 @@ const pluginZodName = "plugin-zod";
|
|
|
2315
2324
|
* })
|
|
2316
2325
|
* ```
|
|
2317
2326
|
*/
|
|
2318
|
-
const pluginZod = (0, kubb_kit.definePlugin)(
|
|
2319
|
-
|
|
2320
|
-
path: "zod",
|
|
2321
|
-
barrel: { type: "named" }
|
|
2322
|
-
}, group, exclude = [], include, override = [], compile = false, mini = false, guidType = "uuid", regexType = "literal", importPath = mini ? "zod/mini" : "zod", coercion = false, inferred = false, typeGuards = false, printer, resolver: userResolver, macros: userMacros } = options;
|
|
2323
|
-
const groupConfig = createGroupConfig(group);
|
|
2324
|
-
return {
|
|
2327
|
+
const pluginZod = (0, kubb_kit.definePlugin)({
|
|
2328
|
+
meta: {
|
|
2325
2329
|
name: pluginZodName,
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2330
|
+
version,
|
|
2331
|
+
compatibility
|
|
2332
|
+
},
|
|
2333
|
+
setup(options) {
|
|
2334
|
+
const { output = {
|
|
2335
|
+
path: "zod",
|
|
2336
|
+
barrel: { type: "named" }
|
|
2337
|
+
}, group, exclude = [], include, override = [], compile = false, mini = false, guidType = "uuid", regexType = "literal", importPath = mini ? "zod/mini" : "zod", coercion = false, inferred = false, typeGuards = false, printer, resolver: userResolver, macros: userMacros } = options;
|
|
2338
|
+
(0, kubb_kit.setResolver)(userResolver ? kubb_kit.Resolver.merge(resolverZod, userResolver) : resolverZod);
|
|
2339
|
+
if (userMacros?.length) (0, kubb_kit.setMacros)(userMacros);
|
|
2340
|
+
(0, kubb_kit.addGenerator)(zodGenerator);
|
|
2341
|
+
return {
|
|
2342
|
+
output,
|
|
2343
|
+
exclude,
|
|
2344
|
+
include,
|
|
2345
|
+
override,
|
|
2346
|
+
group: createGroupConfig(group),
|
|
2347
|
+
importPath,
|
|
2348
|
+
coercion,
|
|
2349
|
+
inferred,
|
|
2350
|
+
guidType,
|
|
2351
|
+
regexType,
|
|
2352
|
+
compile,
|
|
2353
|
+
mini,
|
|
2354
|
+
typeGuards,
|
|
2355
|
+
printer
|
|
2356
|
+
};
|
|
2357
|
+
}
|
|
2349
2358
|
});
|
|
2350
2359
|
//#endregion
|
|
2351
2360
|
exports.default = pluginZod;
|