@kubb/plugin-zod 5.0.0-beta.3 → 5.0.0-beta.30
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/README.md +25 -5
- package/dist/index.cjs +390 -177
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +79 -34
- package/dist/index.js +386 -179
- package/dist/index.js.map +1 -1
- package/extension.yaml +966 -0
- package/package.json +9 -13
- package/src/components/Operations.tsx +4 -4
- package/src/components/Zod.tsx +1 -1
- package/src/generators/zodGenerator.tsx +77 -32
- package/src/plugin.ts +21 -8
- package/src/printers/printerZod.ts +67 -63
- package/src/printers/printerZodMini.ts +46 -49
- package/src/resolvers/resolverZod.ts +25 -19
- package/src/types.ts +42 -21
- package/src/utils.ts +20 -36
package/dist/index.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ 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(() => …)`.
|
|
@@ -121,7 +121,7 @@ type PrinterZodMiniOptions = {
|
|
|
121
121
|
/**
|
|
122
122
|
* Properties to exclude using `.omit({ key: true })`.
|
|
123
123
|
*/
|
|
124
|
-
keysToOmit?: Array<string
|
|
124
|
+
keysToOmit?: Array<string> | null;
|
|
125
125
|
/**
|
|
126
126
|
* Schema names that form circular dependency chains.
|
|
127
127
|
* Properties referencing these emit lazy getters wrapping refs in `z.lazy(() => …)`.
|
|
@@ -222,41 +222,53 @@ type ResolverZod = Resolver & ast.OperationParamsResolver & {
|
|
|
222
222
|
};
|
|
223
223
|
type Options = {
|
|
224
224
|
/**
|
|
225
|
-
*
|
|
225
|
+
* Where the generated Zod schemas are written and how they are exported.
|
|
226
|
+
*
|
|
227
|
+
* @default { path: 'zod', barrel: { type: 'named' } }
|
|
226
228
|
*/
|
|
227
229
|
output?: Output;
|
|
228
230
|
/**
|
|
229
|
-
*
|
|
231
|
+
* Split generated files into subfolders based on the operation's tag.
|
|
230
232
|
*/
|
|
231
233
|
group?: Group;
|
|
232
234
|
/**
|
|
233
|
-
*
|
|
235
|
+
* Skip operations matching at least one entry in the list.
|
|
234
236
|
*/
|
|
235
237
|
exclude?: Array<Exclude>;
|
|
236
238
|
/**
|
|
237
|
-
*
|
|
239
|
+
* Restrict generation to operations matching at least one entry in the list.
|
|
238
240
|
*/
|
|
239
241
|
include?: Array<Include>;
|
|
240
242
|
/**
|
|
241
|
-
*
|
|
243
|
+
* Apply a different options object to operations matching a pattern.
|
|
242
244
|
*/
|
|
243
245
|
override?: Array<Override<ResolvedOptions>>;
|
|
244
246
|
/**
|
|
245
|
-
*
|
|
247
|
+
* Module specifier used in the `import { z } from '...'` statement.
|
|
248
|
+
* Use `'zod/mini'` for the tree-shakeable bundle.
|
|
246
249
|
*
|
|
247
250
|
* @default 'zod'
|
|
248
251
|
*/
|
|
249
252
|
importPath?: 'zod' | 'zod/mini' | (string & {});
|
|
250
253
|
/**
|
|
251
|
-
*
|
|
254
|
+
* Tie each Zod schema to its TypeScript type from `@kubb/plugin-ts`. Requires
|
|
255
|
+
* `@kubb/plugin-ts` in the plugins list. TypeScript fails compilation when the
|
|
256
|
+
* schema drifts from the type.
|
|
252
257
|
*/
|
|
253
258
|
typed?: boolean;
|
|
254
259
|
/**
|
|
255
|
-
*
|
|
260
|
+
* Export a `z.infer<typeof schema>` type alias next to every generated schema.
|
|
261
|
+
* Lets the Zod schema act as the single source of truth.
|
|
256
262
|
*/
|
|
257
263
|
inferred?: boolean;
|
|
258
264
|
/**
|
|
259
|
-
*
|
|
265
|
+
* Wrap schemas in `z.coerce` so input is coerced before validation. Useful for
|
|
266
|
+
* form data and query params where everything arrives as a string.
|
|
267
|
+
* - `true` coerces strings, numbers, and dates.
|
|
268
|
+
* - Object form picks per-primitive coercion.
|
|
269
|
+
*
|
|
270
|
+
* @default false
|
|
271
|
+
* @see https://zod.dev/?id=coercion-for-primitives
|
|
260
272
|
*/
|
|
261
273
|
coercion?: boolean | {
|
|
262
274
|
dates?: boolean;
|
|
@@ -264,50 +276,59 @@ type Options = {
|
|
|
264
276
|
numbers?: boolean;
|
|
265
277
|
};
|
|
266
278
|
/**
|
|
267
|
-
*
|
|
279
|
+
* Emit an `operations.ts` file with request body, query/path params, and per-status
|
|
280
|
+
* response schemas grouped by operation.
|
|
268
281
|
*/
|
|
269
282
|
operations?: boolean;
|
|
270
283
|
/**
|
|
271
|
-
* Validator
|
|
284
|
+
* Validator for `format: uuid` properties.
|
|
285
|
+
* - `'uuid'` — `z.uuid()`. Standard RFC 4122.
|
|
286
|
+
* - `'guid'` — `z.guid()`. Accepts Microsoft-style GUIDs.
|
|
272
287
|
*
|
|
273
288
|
* @default 'uuid'
|
|
274
289
|
*/
|
|
275
290
|
guidType?: 'uuid' | 'guid';
|
|
276
291
|
/**
|
|
277
|
-
*
|
|
292
|
+
* Switch to Zod Mini's functional API for better tree-shaking. Also defaults
|
|
293
|
+
* `importPath` to `'zod/mini'`.
|
|
278
294
|
*
|
|
279
295
|
* @default false
|
|
296
|
+
* @beta
|
|
280
297
|
*/
|
|
281
298
|
mini?: boolean;
|
|
282
299
|
/**
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
300
|
+
* Wrap the generated Zod schema string with extra calls. Receives the raw output
|
|
301
|
+
* and the originating `SchemaNode`. Useful for round-tripping OpenAPI metadata
|
|
302
|
+
* back into Zod (e.g. `.openapi(...)`).
|
|
286
303
|
*/
|
|
287
304
|
wrapOutput?: (arg: {
|
|
288
305
|
output: string;
|
|
289
306
|
schema: ast.SchemaNode;
|
|
290
307
|
}) => string | undefined;
|
|
291
308
|
/**
|
|
292
|
-
*
|
|
309
|
+
* Rename properties inside path/query/header schemas. Body schemas are unaffected.
|
|
310
|
+
*
|
|
311
|
+
* @note Must match the value of `paramsCasing` on `@kubb/plugin-ts`.
|
|
293
312
|
*/
|
|
294
313
|
paramsCasing?: 'camelcase';
|
|
295
314
|
/**
|
|
296
|
-
*
|
|
315
|
+
* Custom generators that run alongside the built-in Zod generators.
|
|
297
316
|
*/
|
|
298
317
|
generators?: Array<Generator<PluginZod>>;
|
|
299
318
|
/**
|
|
300
|
-
* Override
|
|
319
|
+
* Override how schema and operation names are built. Methods you omit fall back
|
|
320
|
+
* to the default `resolverZod`.
|
|
301
321
|
*/
|
|
302
322
|
resolver?: Partial<ResolverZod> & ThisType<ResolverZod>;
|
|
303
323
|
/**
|
|
304
|
-
*
|
|
324
|
+
* Replace the Zod handler for a specific schema type (`'integer'`, `'date'`, ...).
|
|
325
|
+
* When `mini: true`, overrides target the Zod Mini printer instead.
|
|
305
326
|
*/
|
|
306
327
|
printer?: {
|
|
307
328
|
nodes?: PrinterZodNodes | PrinterZodMiniNodes;
|
|
308
329
|
};
|
|
309
330
|
/**
|
|
310
|
-
* AST visitor to
|
|
331
|
+
* AST visitor applied to each schema or operation node before printing.
|
|
311
332
|
*/
|
|
312
333
|
transformer?: ast.Visitor;
|
|
313
334
|
};
|
|
@@ -316,7 +337,7 @@ type ResolvedOptions = {
|
|
|
316
337
|
exclude: Array<Exclude>;
|
|
317
338
|
include: Array<Include> | undefined;
|
|
318
339
|
override: Array<Override<ResolvedOptions>>;
|
|
319
|
-
group: Group |
|
|
340
|
+
group: Group | null;
|
|
320
341
|
typed: NonNullable<Options['typed']>;
|
|
321
342
|
inferred: NonNullable<Options['inferred']>;
|
|
322
343
|
importPath: NonNullable<Options['importPath']>;
|
|
@@ -338,23 +359,42 @@ declare global {
|
|
|
338
359
|
}
|
|
339
360
|
//#endregion
|
|
340
361
|
//#region src/generators/zodGenerator.d.ts
|
|
362
|
+
/**
|
|
363
|
+
* Built-in generator for `@kubb/plugin-zod`. Emits one Zod schema per
|
|
364
|
+
* schema in the spec plus per-operation request/response/parameter schemas.
|
|
365
|
+
* When `mini: true`, schemas use the Zod Mini functional API instead of
|
|
366
|
+
* chainable methods.
|
|
367
|
+
*/
|
|
341
368
|
declare const zodGenerator: _$_kubb_core0.Generator<PluginZod, unknown>;
|
|
342
369
|
//#endregion
|
|
343
370
|
//#region src/plugin.d.ts
|
|
344
371
|
/**
|
|
345
|
-
* Canonical plugin name for `@kubb/plugin-zod
|
|
372
|
+
* Canonical plugin name for `@kubb/plugin-zod`. Used for driver lookups and
|
|
373
|
+
* cross-plugin dependency references.
|
|
346
374
|
*/
|
|
347
375
|
declare const pluginZodName = "plugin-zod";
|
|
348
376
|
/**
|
|
349
|
-
* Generates Zod
|
|
350
|
-
*
|
|
351
|
-
*
|
|
377
|
+
* Generates Zod v4 schemas from an OpenAPI spec. Use them to validate API
|
|
378
|
+
* responses at runtime, build form schemas, or feed back into router libraries
|
|
379
|
+
* that consume Zod (tRPC, Hono, Elysia). Pair with `@kubb/plugin-client` and
|
|
380
|
+
* set the client's `parser: 'zod'` to validate every response automatically.
|
|
352
381
|
*
|
|
353
|
-
* @example
|
|
382
|
+
* @example
|
|
354
383
|
* ```ts
|
|
355
|
-
* import
|
|
384
|
+
* import { defineConfig } from 'kubb'
|
|
385
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
386
|
+
* import { pluginZod } from '@kubb/plugin-zod'
|
|
387
|
+
*
|
|
356
388
|
* export default defineConfig({
|
|
357
|
-
*
|
|
389
|
+
* input: { path: './petStore.yaml' },
|
|
390
|
+
* output: { path: './src/gen' },
|
|
391
|
+
* plugins: [
|
|
392
|
+
* pluginTs(),
|
|
393
|
+
* pluginZod({
|
|
394
|
+
* output: { path: './zod' },
|
|
395
|
+
* typed: true,
|
|
396
|
+
* }),
|
|
397
|
+
* ],
|
|
358
398
|
* })
|
|
359
399
|
* ```
|
|
360
400
|
*/
|
|
@@ -362,12 +402,17 @@ declare const pluginZod: (options?: Options | undefined) => _$_kubb_core0.Plugin
|
|
|
362
402
|
//#endregion
|
|
363
403
|
//#region src/resolvers/resolverZod.d.ts
|
|
364
404
|
/**
|
|
365
|
-
*
|
|
405
|
+
* Default resolver used by `@kubb/plugin-zod`. Decides the names and file
|
|
406
|
+
* paths for every generated Zod schema. Schemas use camelCase with a
|
|
407
|
+
* `Schema` suffix (`listPetsSchema`); their inferred types use PascalCase.
|
|
366
408
|
*
|
|
367
|
-
*
|
|
409
|
+
* @example Resolve schema and type names
|
|
410
|
+
* ```ts
|
|
411
|
+
* import { resolverZod } from '@kubb/plugin-zod'
|
|
368
412
|
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
413
|
+
* resolverZod.default('list pets', 'function') // 'listPetsSchema'
|
|
414
|
+
* resolverZod.resolveSchemaTypeName('pet') // 'PetSchema'
|
|
415
|
+
* ```
|
|
371
416
|
*/
|
|
372
417
|
declare const resolverZod: ResolverZod;
|
|
373
418
|
//#endregion
|