@kubb/plugin-zod 5.0.0-beta.4 → 5.0.0-beta.56

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/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { t as __name } from "./chunk--u3MIqq1.js";
2
- import * as _$_kubb_core0 from "@kubb/core";
3
- import { Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
1
+ import { t as __name } from "./chunk-C0LytTxp.js";
2
+ import { Exclude, Generator, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
4
3
  import { AdapterOas } from "@kubb/adapter-oas";
5
4
 
6
5
  //#region src/printers/printerZod.d.ts
@@ -51,12 +50,21 @@ type PrinterZodOptions = {
51
50
  /**
52
51
  * Properties to exclude using `.omit({ key: true })`.
53
52
  */
54
- keysToOmit?: Array<string>;
53
+ keysToOmit?: Array<string> | null;
55
54
  /**
56
55
  * Schema names that form circular dependency chains.
57
56
  * Properties referencing these emit lazy getters wrapping refs in `z.lazy(() => …)`.
58
57
  */
59
58
  cyclicSchemas?: ReadonlySet<string>;
59
+ /**
60
+ * Print direction for `dateType: 'date'` fields (`Date` in TypeScript):
61
+ * - `'output'` (default) — decode the wire `string` into a `Date` (response bodies).
62
+ * - `'input'` — encode a `Date` back into the wire `string` (request bodies/params).
63
+ *
64
+ * Diverging the directions requires the generator to emit an `${name}InputSchema`
65
+ * variant for each date-bearing component.
66
+ */
67
+ direction?: 'input' | 'output';
60
68
  /**
61
69
  * Custom handler map for node type overrides.
62
70
  */
@@ -121,7 +129,7 @@ type PrinterZodMiniOptions = {
121
129
  /**
122
130
  * Properties to exclude using `.omit({ key: true })`.
123
131
  */
124
- keysToOmit?: Array<string>;
132
+ keysToOmit?: Array<string> | null;
125
133
  /**
126
134
  * Schema names that form circular dependency chains.
127
135
  * Properties referencing these emit lazy getters wrapping refs in `z.lazy(() => …)`.
@@ -163,14 +171,29 @@ type ResolverZod = Resolver & ast.OperationParamsResolver & {
163
171
  * Resolves the schema type name (inferred type from schema).
164
172
  *
165
173
  * @example Schema type names
166
- * `resolver.resolveSchemaTypeName('pet') // → 'Pet'`
174
+ * `resolver.resolveSchemaTypeName('pet') // → 'PetSchemaType'`
167
175
  */
168
176
  resolveSchemaTypeName(this: ResolverZod, name: string): string;
177
+ /**
178
+ * Resolves the schema function name for the request (input) direction of a
179
+ * date-bearing component, where `Date` is encoded back to a wire `string`.
180
+ *
181
+ * @example Input schema names
182
+ * `resolver.resolveInputSchemaName('order') // → 'orderInputSchema'`
183
+ */
184
+ resolveInputSchemaName(this: ResolverZod, name: string): string;
185
+ /**
186
+ * Resolves the inferred type name for the request (input) direction variant.
187
+ *
188
+ * @example Input schema type names
189
+ * `resolver.resolveInputSchemaTypeName('order') // → 'OrderInputSchemaType'`
190
+ */
191
+ resolveInputSchemaTypeName(this: ResolverZod, name: string): string;
169
192
  /**
170
193
  * Resolves the generated type name from the schema.
171
194
  *
172
195
  * @example Type names
173
- * `resolver.resolveTypeName('pet') // → 'Pet'`
196
+ * `resolver.resolveTypeName('petSchema') // → 'PetSchemaType'`
174
197
  */
175
198
  resolveTypeName(this: ResolverZod, name: string): string;
176
199
  /**
@@ -220,43 +243,51 @@ type ResolverZod = Resolver & ast.OperationParamsResolver & {
220
243
  */
221
244
  resolveHeaderParamsName(this: ResolverZod, node: ast.OperationNode, param: ast.ParameterNode): string;
222
245
  };
223
- type Options = {
224
- /**
225
- * @default 'zod'
226
- */
227
- output?: Output;
228
- /**
229
- * Group the Zod schemas based on the provided name.
230
- */
231
- group?: Group;
246
+ /**
247
+ * Where the generated Zod schemas are written and how they are exported, plus the optional
248
+ * `group` strategy. The `group` option organizes `output.mode: 'directory'` output into per-tag or per-path subdirectories.
249
+ *
250
+ * @default { path: 'zod', barrel: { type: 'named' } }
251
+ */
252
+ type Options = OutputOptions & {
232
253
  /**
233
- * Tags, operations, or paths to exclude from generation.
254
+ * Skip operations matching at least one entry in the list.
234
255
  */
235
256
  exclude?: Array<Exclude>;
236
257
  /**
237
- * Tags, operations, or paths to include in generation.
258
+ * Restrict generation to operations matching at least one entry in the list.
238
259
  */
239
260
  include?: Array<Include>;
240
261
  /**
241
- * Override options for specific tags, operations, or paths.
262
+ * Apply a different options object to operations matching a pattern.
242
263
  */
243
264
  override?: Array<Override<ResolvedOptions>>;
244
265
  /**
245
- * Import path for Zod package.
266
+ * Module specifier used in the `import { z } from '...'` statement.
267
+ * Use `'zod/mini'` for the tree-shakeable bundle.
246
268
  *
247
- * @default 'zod'
269
+ * @default mini ? 'zod/mini' : 'zod'
248
270
  */
249
271
  importPath?: 'zod' | 'zod/mini' | (string & {});
250
272
  /**
251
- * Add TypeScript type annotations to generated schemas.
273
+ * Tie each Zod schema to its TypeScript type from `@kubb/plugin-ts`. Requires
274
+ * `@kubb/plugin-ts` in the plugins list. TypeScript fails compilation when the
275
+ * schema drifts from the type.
252
276
  */
253
277
  typed?: boolean;
254
278
  /**
255
- * Return schemas as inferred types using `z.infer`.
279
+ * Export a `z.infer<typeof schema>` type alias next to every generated schema.
280
+ * Lets the Zod schema act as the single source of truth.
256
281
  */
257
282
  inferred?: boolean;
258
283
  /**
259
- * Apply coercion to string values or configure coercion per type.
284
+ * Wrap schemas in `z.coerce` so input is coerced before validation. Useful for
285
+ * form data and query params where everything arrives as a string.
286
+ * - `true` coerces strings, numbers, and dates.
287
+ * - Object form picks per-primitive coercion.
288
+ *
289
+ * @default false
290
+ * @see https://zod.dev/?id=coercion-for-primitives
260
291
  */
261
292
  coercion?: boolean | {
262
293
  dates?: boolean;
@@ -264,50 +295,59 @@ type Options = {
264
295
  numbers?: boolean;
265
296
  };
266
297
  /**
267
- * Generate operation-level schemas (grouped by operationId).
298
+ * Emit an `operations.ts` file with request body, query/path params, and per-status
299
+ * response schemas grouped by operation.
268
300
  */
269
301
  operations?: boolean;
270
302
  /**
271
- * Validator to use for UUID format: `uuid` or `guid`.
303
+ * Validator for `format: uuid` properties.
304
+ * - `'uuid'` — `z.uuid()`. Standard RFC 4122.
305
+ * - `'guid'` — `z.guid()`. Accepts Microsoft-style GUIDs.
272
306
  *
273
307
  * @default 'uuid'
274
308
  */
275
309
  guidType?: 'uuid' | 'guid';
276
310
  /**
277
- * Use Zod Mini's functional API for better tree-shaking.
311
+ * Switch to Zod Mini's functional API for better tree-shaking. Also defaults
312
+ * `importPath` to `'zod/mini'`.
278
313
  *
279
314
  * @default false
315
+ * @beta
280
316
  */
281
317
  mini?: boolean;
282
318
  /**
283
- * Callback to wrap the generated schema output.
284
- *
285
- * Useful for adding metadata like `.openapi()` or extension helpers.
319
+ * Wrap the generated Zod schema string with extra calls. Receives the raw output
320
+ * and the originating `SchemaNode`. Useful for round-tripping OpenAPI metadata
321
+ * back into Zod (e.g. `.openapi(...)`).
286
322
  */
287
323
  wrapOutput?: (arg: {
288
324
  output: string;
289
325
  schema: ast.SchemaNode;
290
326
  }) => string | undefined;
291
327
  /**
292
- * Apply casing to parameter names.
328
+ * Rename properties inside path/query/header schemas. Body schemas are unaffected.
329
+ *
330
+ * @note Must match the value of `paramsCasing` on `@kubb/plugin-ts`.
293
331
  */
294
332
  paramsCasing?: 'camelcase';
295
333
  /**
296
- * Additional generators alongside the default generators.
334
+ * Custom generators that run alongside the built-in Zod generators.
297
335
  */
298
336
  generators?: Array<Generator<PluginZod>>;
299
337
  /**
300
- * Override naming conventions for schema names and types.
338
+ * Override how schema and operation names are built. Methods you omit fall back
339
+ * to the default `resolverZod`.
301
340
  */
302
341
  resolver?: Partial<ResolverZod> & ThisType<ResolverZod>;
303
342
  /**
304
- * Override printer node handlers to customize rendering of specific schema types.
343
+ * Replace the Zod handler for a specific schema type (`'integer'`, `'date'`, ...).
344
+ * When `mini: true`, overrides target the Zod Mini printer instead.
305
345
  */
306
346
  printer?: {
307
347
  nodes?: PrinterZodNodes | PrinterZodMiniNodes;
308
348
  };
309
349
  /**
310
- * AST visitor to transform schema and operation nodes.
350
+ * AST visitor applied to each schema or operation node before printing.
311
351
  */
312
352
  transformer?: ast.Visitor;
313
353
  };
@@ -316,7 +356,7 @@ type ResolvedOptions = {
316
356
  exclude: Array<Exclude>;
317
357
  include: Array<Include> | undefined;
318
358
  override: Array<Override<ResolvedOptions>>;
319
- group: Group | undefined;
359
+ group: Group | null;
320
360
  typed: NonNullable<Options['typed']>;
321
361
  inferred: NonNullable<Options['inferred']>;
322
362
  importPath: NonNullable<Options['importPath']>;
@@ -338,36 +378,62 @@ declare global {
338
378
  }
339
379
  //#endregion
340
380
  //#region src/generators/zodGenerator.d.ts
341
- declare const zodGenerator: _$_kubb_core0.Generator<PluginZod, unknown>;
381
+ /**
382
+ * Built-in generator for `@kubb/plugin-zod`. Emits one Zod schema per
383
+ * schema in the spec plus per-operation request/response/parameter schemas.
384
+ * When `mini: true`, schemas use the Zod Mini functional API instead of
385
+ * chainable methods.
386
+ */
387
+ declare const zodGenerator: import("@kubb/core").Generator<PluginZod, unknown>;
342
388
  //#endregion
343
389
  //#region src/plugin.d.ts
344
390
  /**
345
- * Canonical plugin name for `@kubb/plugin-zod`, used in driver lookups and warnings.
391
+ * Canonical plugin name for `@kubb/plugin-zod`. Used for driver lookups and
392
+ * cross-plugin dependency references.
346
393
  */
347
394
  declare const pluginZodName = "plugin-zod";
348
395
  /**
349
- * Generates Zod validation schemas from an OpenAPI specification.
350
- * Walks schemas and operations, delegates to generators, and writes barrel files
351
- * based on the configured `barrelType`.
396
+ * Generates Zod v4 schemas from an OpenAPI spec. Use them to validate API
397
+ * responses at runtime, build form schemas, or feed back into router libraries
398
+ * that consume Zod (tRPC, Hono, Elysia). Pair with `@kubb/plugin-client` and
399
+ * set the client's `parser: 'zod'` to validate every response automatically.
352
400
  *
353
- * @example Zod schema generator
401
+ * @example
354
402
  * ```ts
355
- * import pluginZod from '@kubb/plugin-zod'
403
+ * import { defineConfig } from 'kubb'
404
+ * import { pluginTs } from '@kubb/plugin-ts'
405
+ * import { pluginZod } from '@kubb/plugin-zod'
406
+ *
356
407
  * export default defineConfig({
357
- * plugins: [pluginZod({ output: { path: 'zod' } })]
408
+ * input: { path: './petStore.yaml' },
409
+ * output: { path: './src/gen' },
410
+ * plugins: [
411
+ * pluginTs(),
412
+ * pluginZod({
413
+ * output: { path: './zod' },
414
+ * typed: true,
415
+ * }),
416
+ * ],
358
417
  * })
359
418
  * ```
360
419
  */
361
- declare const pluginZod: (options?: Options | undefined) => _$_kubb_core0.Plugin<PluginZod>;
420
+ declare const pluginZod: (options?: Options | undefined) => import("@kubb/core").Plugin<PluginZod>;
362
421
  //#endregion
363
422
  //#region src/resolvers/resolverZod.d.ts
364
423
  /**
365
- * Naming convention resolver for Zod plugin.
424
+ * Default resolver used by `@kubb/plugin-zod`. Decides the names and file
425
+ * paths for every generated Zod schema. Schemas use camelCase with a
426
+ * `Schema` suffix (`listPetsSchema`); their inferred types use PascalCase
427
+ * with a `SchemaType` suffix (`PetSchemaType`), so the value and the type
428
+ * never share an identifier even when the schema name is all-uppercase.
366
429
  *
367
- * Provides default naming helpers using camelCase with a `Schema` suffix for schemas.
430
+ * @example Resolve schema and type names
431
+ * ```ts
432
+ * import { resolverZod } from '@kubb/plugin-zod'
368
433
  *
369
- * @example
370
- * `resolverZod.default('list pets', 'function') // 'listPetsSchema'`
434
+ * resolverZod.default('list pets', 'function') // 'listPetsSchema'
435
+ * resolverZod.resolveSchemaTypeName('pet') // 'PetSchemaType'
436
+ * ```
371
437
  */
372
438
  declare const resolverZod: ResolverZod;
373
439
  //#endregion