@kubb/plugin-zod 5.0.0-beta.3 → 5.0.0-beta.31

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