@kubb/plugin-zod 5.4.9 → 5.4.12
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.cjs +171 -282
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +555 -0
- package/dist/index.d.ts +1 -3
- package/dist/index.js +172 -277
- package/dist/index.js.map +1 -1
- package/kubb-extension.json +1 -1
- package/package.json +13 -8
- package/dist/rolldown-runtime-C0LytTxp.js +0 -8
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
2
|
+
//#region src/printers/printerZod.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Partial map of node-type overrides for the Zod printer.
|
|
5
|
+
*
|
|
6
|
+
* Each key is a `SchemaType` string (e.g. `'date'`, `'string'`). The function
|
|
7
|
+
* replaces the built-in handler for that node type. Use `this.transform` to
|
|
8
|
+
* recurse into nested schema nodes, `this.base` to reuse the output of the
|
|
9
|
+
* handler being replaced, and `this.options` to read printer options.
|
|
10
|
+
*
|
|
11
|
+
* @example Override the `date` handler
|
|
12
|
+
* ```ts
|
|
13
|
+
* pluginZod({
|
|
14
|
+
* printer: {
|
|
15
|
+
* nodes: {
|
|
16
|
+
* date(node) {
|
|
17
|
+
* return 'z.iso.date()'
|
|
18
|
+
* },
|
|
19
|
+
* },
|
|
20
|
+
* },
|
|
21
|
+
* })
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @example Wrap the built-in output
|
|
25
|
+
* ```ts
|
|
26
|
+
* pluginZod({
|
|
27
|
+
* printer: {
|
|
28
|
+
* nodes: {
|
|
29
|
+
* object(node) {
|
|
30
|
+
* return `${this.base(node)}.openapi(${JSON.stringify({ description: node.description })})`
|
|
31
|
+
* },
|
|
32
|
+
* },
|
|
33
|
+
* },
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
type PrinterZodNodes = ast.PrinterPartial<string, PrinterZodOptions>;
|
|
38
|
+
type PrinterZodOptions = {
|
|
39
|
+
/**
|
|
40
|
+
* Enable automatic type coercion for strings, numbers, and dates.
|
|
41
|
+
*/
|
|
42
|
+
coercion?: PluginZod['resolvedOptions']['coercion'];
|
|
43
|
+
/**
|
|
44
|
+
* Use `z.guid()` or `z.uuid()` for UUID/GUID validation.
|
|
45
|
+
*
|
|
46
|
+
* @default 'uuid'
|
|
47
|
+
*/
|
|
48
|
+
guidType?: PluginZod['resolvedOptions']['guidType'];
|
|
49
|
+
/**
|
|
50
|
+
* Output form for an OpenAPI `pattern` inside `.regex(...)`: a regex literal
|
|
51
|
+
* (`'literal'`) or the `RegExp` constructor (`'constructor'`).
|
|
52
|
+
*
|
|
53
|
+
* @default 'literal'
|
|
54
|
+
*/
|
|
55
|
+
regexType?: PluginZod['resolvedOptions']['regexType'];
|
|
56
|
+
/**
|
|
57
|
+
* Date format in the OpenAPI spec (`'date'` or `'date-time'`).
|
|
58
|
+
*/
|
|
59
|
+
dateType?: ast.ParserOptions['dateType'];
|
|
60
|
+
/**
|
|
61
|
+
* Transforms raw schema names into valid JavaScript identifiers.
|
|
62
|
+
*/
|
|
63
|
+
resolver?: ResolverZod;
|
|
64
|
+
/**
|
|
65
|
+
* Properties to exclude using `.omit({ key: true })`.
|
|
66
|
+
*/
|
|
67
|
+
keysToOmit?: Array<string> | null;
|
|
68
|
+
/**
|
|
69
|
+
* Schema names that form circular dependency chains.
|
|
70
|
+
* Properties referencing these emit lazy getters wrapping refs in `z.lazy(() => …)`.
|
|
71
|
+
*/
|
|
72
|
+
cyclicSchemas?: ReadonlySet<string>;
|
|
73
|
+
/**
|
|
74
|
+
* Which way a node converts between its wire type and its runtime type:
|
|
75
|
+
* - `'decode'` (default): wire into runtime, used by response schemas.
|
|
76
|
+
* - `'encode'`: runtime back to wire, used by request bodies and parameters.
|
|
77
|
+
*
|
|
78
|
+
* Named for the conversion rather than the slot, since Zod's own `z.input` and `z.output`
|
|
79
|
+
* describe a different axis and read inverted here: the `'decode'` schema is the one whose
|
|
80
|
+
* `z.input` is the wire type.
|
|
81
|
+
*
|
|
82
|
+
* A handler returning different output per direction makes the generator emit an
|
|
83
|
+
* `${name}InputSchema` variant for that component.
|
|
84
|
+
*/
|
|
85
|
+
direction?: 'encode' | 'decode';
|
|
86
|
+
/**
|
|
87
|
+
* Custom handler map for node type overrides.
|
|
88
|
+
*/
|
|
89
|
+
nodes?: PrinterZodNodes;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Factory options for the Zod printer, defining input/output types and configuration.
|
|
93
|
+
*/
|
|
94
|
+
type PrinterZodFactory = ast.PrinterFactoryOptions<'zod', PrinterZodOptions, string, string>;
|
|
95
|
+
/**
|
|
96
|
+
* Zod v4 printer built with `definePrinter`.
|
|
97
|
+
*
|
|
98
|
+
* Converts a `SchemaNode` AST into a Zod v4 code string using the chainable API
|
|
99
|
+
* (`.optional()`, `.nullable()`, `.omit()`, etc.). For improved tree-shaking, see {@link printerZodMini}.
|
|
100
|
+
*
|
|
101
|
+
* @example Chainable API
|
|
102
|
+
* ```ts
|
|
103
|
+
* const printer = printerZod({ coercion: false })
|
|
104
|
+
* const code = printer.print(stringNode) // "z.string()"
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare const printerZod: (options?: PrinterZodOptions | undefined) => ast.Printer<PrinterZodFactory>;
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/printers/printerZodMini.d.ts
|
|
110
|
+
/**
|
|
111
|
+
* Partial map of node-type overrides for the Zod Mini printer.
|
|
112
|
+
*
|
|
113
|
+
* Each key is a `SchemaType` string (e.g. `'date'`, `'string'`). The function
|
|
114
|
+
* replaces the built-in handler for that node type. Use `this.transform` to
|
|
115
|
+
* recurse into nested schema nodes, `this.base` to reuse the output of the
|
|
116
|
+
* handler being replaced, and `this.options` to read printer options.
|
|
117
|
+
*
|
|
118
|
+
* @example Override the `date` handler
|
|
119
|
+
* ```ts
|
|
120
|
+
* pluginZod({
|
|
121
|
+
* mini: true,
|
|
122
|
+
* printer: {
|
|
123
|
+
* nodes: {
|
|
124
|
+
* date(node) {
|
|
125
|
+
* return 'z.iso.date()'
|
|
126
|
+
* },
|
|
127
|
+
* },
|
|
128
|
+
* },
|
|
129
|
+
* })
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
type PrinterZodMiniNodes = ast.PrinterPartial<string, PrinterZodMiniOptions>;
|
|
133
|
+
type PrinterZodMiniOptions = {
|
|
134
|
+
/**
|
|
135
|
+
* Enable automatic type coercion for strings, numbers, and dates through `z.coerce.*()`.
|
|
136
|
+
*/
|
|
137
|
+
coercion?: PluginZod['resolvedOptions']['coercion'];
|
|
138
|
+
/**
|
|
139
|
+
* Use `z.guid()` or `z.uuid()` for UUID/GUID validation.
|
|
140
|
+
*
|
|
141
|
+
* @default 'uuid'
|
|
142
|
+
*/
|
|
143
|
+
guidType?: PluginZod['resolvedOptions']['guidType'];
|
|
144
|
+
/**
|
|
145
|
+
* Output form for an OpenAPI `pattern` inside `z.regex(...)`: a regex literal
|
|
146
|
+
* (`'literal'`) or the `RegExp` constructor (`'constructor'`).
|
|
147
|
+
*
|
|
148
|
+
* @default 'literal'
|
|
149
|
+
*/
|
|
150
|
+
regexType?: PluginZod['resolvedOptions']['regexType'];
|
|
151
|
+
/**
|
|
152
|
+
* Transforms raw schema names into valid JavaScript identifiers.
|
|
153
|
+
*/
|
|
154
|
+
resolver?: ResolverZod;
|
|
155
|
+
/**
|
|
156
|
+
* Properties to exclude using `.omit({ key: true })`.
|
|
157
|
+
*/
|
|
158
|
+
keysToOmit?: Array<string> | null;
|
|
159
|
+
/**
|
|
160
|
+
* Schema names that form circular dependency chains.
|
|
161
|
+
* Properties referencing these emit lazy getters wrapping refs in `z.lazy(() => …)`.
|
|
162
|
+
*/
|
|
163
|
+
cyclicSchemas?: ReadonlySet<string>;
|
|
164
|
+
/**
|
|
165
|
+
* Custom handler map for node type overrides.
|
|
166
|
+
*/
|
|
167
|
+
nodes?: PrinterZodMiniNodes;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Factory options for the Zod Mini printer, defining input/output types and configuration.
|
|
171
|
+
*/
|
|
172
|
+
type PrinterZodMiniFactory = ast.PrinterFactoryOptions<'zod-mini', PrinterZodMiniOptions, string, string>;
|
|
173
|
+
/**
|
|
174
|
+
* Zod v4 Mini printer built with `definePrinter`.
|
|
175
|
+
*
|
|
176
|
+
* Converts a `SchemaNode` AST into a Zod v4 code string using the functional API
|
|
177
|
+
* (`z.optional(z.string())`) for improved tree-shaking. See {@link printerZod} for the chainable API.
|
|
178
|
+
*
|
|
179
|
+
* @example Functional Mini API
|
|
180
|
+
* ```ts
|
|
181
|
+
* const printer = printerZodMini({})
|
|
182
|
+
* const code = printer.print(optionalStringNode) // "z.optional(z.string())"
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
export declare const printerZodMini: (options?: PrinterZodMiniOptions | undefined) => ast.Printer<PrinterZodMiniFactory>;
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/types.d.ts
|
|
188
|
+
/**
|
|
189
|
+
* Resolver for Zod that provides naming methods for schema types.
|
|
190
|
+
*
|
|
191
|
+
* The top-level `name` resolves a camelCase schema function name with a `Schema` suffix
|
|
192
|
+
* (`listPetsSchema`), and `file` casts generated file names the same way. Composite naming lives in
|
|
193
|
+
* the `schema`, `param`, and `response` namespaces.
|
|
194
|
+
*/
|
|
195
|
+
type ResolverZod = Resolver & {
|
|
196
|
+
/**
|
|
197
|
+
* Names derived from a component schema: its inferred types and the request (input) direction
|
|
198
|
+
* variant, where a date-bearing component encodes `Date` back to a wire `string`.
|
|
199
|
+
*/
|
|
200
|
+
schema: {
|
|
201
|
+
/**
|
|
202
|
+
* Resolves the schema type name (inferred type from schema).
|
|
203
|
+
*
|
|
204
|
+
* @example Schema type names
|
|
205
|
+
* `resolver.schema.typeName('pet') // → 'PetSchemaType'`
|
|
206
|
+
*/
|
|
207
|
+
typeName(name: string): string;
|
|
208
|
+
/**
|
|
209
|
+
* Resolves the generated type name from the schema.
|
|
210
|
+
*
|
|
211
|
+
* @example Type names
|
|
212
|
+
* `resolver.schema.type('petSchema') // → 'PetSchemaType'`
|
|
213
|
+
*/
|
|
214
|
+
type(name: string): string;
|
|
215
|
+
/**
|
|
216
|
+
* Resolves the schema function name for the request (input) direction of a
|
|
217
|
+
* date-bearing component, where `Date` is encoded back to a wire `string`.
|
|
218
|
+
*
|
|
219
|
+
* @example Input schema names
|
|
220
|
+
* `resolver.schema.inputName('order') // → 'orderInputSchema'`
|
|
221
|
+
*/
|
|
222
|
+
inputName(name: string): string;
|
|
223
|
+
/**
|
|
224
|
+
* Resolves the inferred type name for the request (input) direction variant.
|
|
225
|
+
*
|
|
226
|
+
* @example Input schema type names
|
|
227
|
+
* `resolver.schema.inputTypeName('order') // → 'OrderInputSchemaType'`
|
|
228
|
+
*/
|
|
229
|
+
inputTypeName(name: string): string;
|
|
230
|
+
/**
|
|
231
|
+
* Resolves the type guard function name for a schema.
|
|
232
|
+
*
|
|
233
|
+
* @example Type guard names
|
|
234
|
+
* `resolver.schema.isName('pet') // → 'isPet'`
|
|
235
|
+
*/
|
|
236
|
+
isName(name: string): string;
|
|
237
|
+
/**
|
|
238
|
+
* Resolves the assertion function name for a schema.
|
|
239
|
+
*
|
|
240
|
+
* @example Assertion names
|
|
241
|
+
* `resolver.schema.assertName('pet') // → 'assertPet'`
|
|
242
|
+
*/
|
|
243
|
+
assertName(name: string): string;
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* Names for an operation's parameters: an individual parameter and the grouped path, query, and
|
|
247
|
+
* header schemas.
|
|
248
|
+
*/
|
|
249
|
+
param: {
|
|
250
|
+
/**
|
|
251
|
+
* Resolves the schema name for an individual parameter.
|
|
252
|
+
*
|
|
253
|
+
* @example Individual parameter name
|
|
254
|
+
* `resolver.param.name(node, param) // → 'deletePetPathPetIdSchema'`
|
|
255
|
+
*/
|
|
256
|
+
name(node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
257
|
+
/**
|
|
258
|
+
* Resolves the name for an operation's grouped path parameters schema.
|
|
259
|
+
*
|
|
260
|
+
* @example Path parameters names
|
|
261
|
+
* `resolver.param.path(node, param) // → 'deletePetPathSchema'`
|
|
262
|
+
*/
|
|
263
|
+
path(node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
264
|
+
/**
|
|
265
|
+
* Resolves the name for an operation's grouped query parameters schema.
|
|
266
|
+
*
|
|
267
|
+
* @example Query parameters names
|
|
268
|
+
* `resolver.param.query(node, param) // → 'findPetsByStatusQuerySchema'`
|
|
269
|
+
*/
|
|
270
|
+
query(node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
271
|
+
/**
|
|
272
|
+
* Resolves the name for an operation's grouped header parameters schema.
|
|
273
|
+
*
|
|
274
|
+
* @example Header parameters names
|
|
275
|
+
* `resolver.param.headers(node, param) // → 'deletePetHeadersSchema'`
|
|
276
|
+
*/
|
|
277
|
+
headers(node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
278
|
+
};
|
|
279
|
+
/**
|
|
280
|
+
* Names for an operation's responses: per-status schemas, the request body, and the combined,
|
|
281
|
+
* union, and error names.
|
|
282
|
+
*/
|
|
283
|
+
response: {
|
|
284
|
+
/**
|
|
285
|
+
* Resolves the name for an operation response by status code.
|
|
286
|
+
*
|
|
287
|
+
* @example Response status names
|
|
288
|
+
* `resolver.response.status(node, 200) // → 'listPetsStatus200Schema'`
|
|
289
|
+
*/
|
|
290
|
+
status(node: ast.OperationNode, statusCode: ast.StatusCode): string;
|
|
291
|
+
/**
|
|
292
|
+
* Resolves the request body schema name.
|
|
293
|
+
*
|
|
294
|
+
* @example Request body names
|
|
295
|
+
* `resolver.response.body(node) // → 'createPetBodySchema'`
|
|
296
|
+
*/
|
|
297
|
+
body(node: ast.OperationNode): string;
|
|
298
|
+
/**
|
|
299
|
+
* Resolves the name for the per-status record of all operation responses. Only meaningful when
|
|
300
|
+
* `inferred: true`, since the schema and type this name points to are generated only in that
|
|
301
|
+
* case. Generated clients key their `RequestResult` on the inferred type.
|
|
302
|
+
*
|
|
303
|
+
* @example Responses collection names
|
|
304
|
+
* `resolver.response.responses(node) // → 'listPetsResponsesSchema'`
|
|
305
|
+
*/
|
|
306
|
+
responses(node: ast.OperationNode): string;
|
|
307
|
+
/**
|
|
308
|
+
* Resolves the name for the union of all operation responses.
|
|
309
|
+
*
|
|
310
|
+
* @example Response union names
|
|
311
|
+
* `resolver.response.response(node) // → 'listPetsResponseSchema'`
|
|
312
|
+
*/
|
|
313
|
+
response(node: ast.OperationNode): string;
|
|
314
|
+
/**
|
|
315
|
+
* Resolves the name for the union of an operation's error (non-2xx) responses. Generated clients
|
|
316
|
+
* validate the error body against this on the non-throw path.
|
|
317
|
+
*
|
|
318
|
+
* @example Error union names
|
|
319
|
+
* `resolver.response.error(node) // → 'listPetsErrorSchema'`
|
|
320
|
+
*/
|
|
321
|
+
error(node: ast.OperationNode): string;
|
|
322
|
+
/**
|
|
323
|
+
* Resolves the inferred type name for an operation's combined `{ body, path, query, headers }`
|
|
324
|
+
* options object. Only meaningful when `inferred: true`, since the schema and type this name
|
|
325
|
+
* points to are generated only in that case.
|
|
326
|
+
*
|
|
327
|
+
* @example Options type names
|
|
328
|
+
* `resolver.response.options(node) // → 'ListPetsOptionsSchemaType'`
|
|
329
|
+
*/
|
|
330
|
+
options(node: ast.OperationNode): string;
|
|
331
|
+
};
|
|
332
|
+
};
|
|
333
|
+
type CompileOptions = {
|
|
334
|
+
/**
|
|
335
|
+
* Throw an error if any part of the schema cannot be compiled into flat JavaScript,
|
|
336
|
+
* preventing silent fallback to the standard interpreter.
|
|
337
|
+
*
|
|
338
|
+
* @default false
|
|
339
|
+
*/
|
|
340
|
+
strict?: boolean;
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* Where the generated Zod schemas are written and how they are exported, plus the optional
|
|
344
|
+
* `group` strategy. The `group` option organizes `output.mode: 'directory'` output into per-tag or per-path subdirectories.
|
|
345
|
+
*
|
|
346
|
+
* @default { path: 'zod', barrel: { type: 'named' } }
|
|
347
|
+
*/
|
|
348
|
+
type Options = OutputOptions & {
|
|
349
|
+
/**
|
|
350
|
+
* Skip operations matching at least one entry in the list.
|
|
351
|
+
*/
|
|
352
|
+
exclude?: Array<Exclude>;
|
|
353
|
+
/**
|
|
354
|
+
* Restrict generation to operations matching at least one entry in the list.
|
|
355
|
+
*/
|
|
356
|
+
include?: Array<Include>;
|
|
357
|
+
/**
|
|
358
|
+
* Apply a different options object to operations matching a pattern.
|
|
359
|
+
*/
|
|
360
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
361
|
+
/**
|
|
362
|
+
* Module specifier used in the `import { z } from '...'` statement.
|
|
363
|
+
* Use `'zod/mini'` for the tree-shakeable bundle.
|
|
364
|
+
*
|
|
365
|
+
* @default mini ? 'zod/mini' : 'zod'
|
|
366
|
+
*/
|
|
367
|
+
importPath?: 'zod' | 'zod/mini' | (string & {});
|
|
368
|
+
/**
|
|
369
|
+
* Export a `z.infer<typeof schema>` type alias next to every generated schema.
|
|
370
|
+
* Lets the Zod schema act as the single source of truth.
|
|
371
|
+
*/
|
|
372
|
+
inferred?: boolean;
|
|
373
|
+
/**
|
|
374
|
+
* Wrap schemas in `z.coerce` so input is coerced before validation. Useful for
|
|
375
|
+
* form data and query params where everything arrives as a string.
|
|
376
|
+
* - `true` coerces strings, numbers, and dates.
|
|
377
|
+
* - Object form picks per-primitive coercion.
|
|
378
|
+
*
|
|
379
|
+
* `dates` applies to fields typed as `Date` (adapter `dateType: 'date'`): they
|
|
380
|
+
* validate with `z.coerce.date()` instead of the string-to-Date codec. Fields
|
|
381
|
+
* kept as ISO strings (`z.iso.date()`, `z.iso.datetime()`) are never coerced,
|
|
382
|
+
* and neither are `format: time` fields, since `new Date()` cannot parse a bare
|
|
383
|
+
* `HH:mm:ss` value.
|
|
384
|
+
*
|
|
385
|
+
* `bigint` fields (`format: int64`) always coerce, regardless of this option:
|
|
386
|
+
* `JSON.parse` hands back a `number`, which a plain `z.bigint()` rejects.
|
|
387
|
+
*
|
|
388
|
+
* @default false
|
|
389
|
+
* @see https://zod.dev/?id=coercion-for-primitives
|
|
390
|
+
*/
|
|
391
|
+
coercion?: boolean | {
|
|
392
|
+
dates?: boolean;
|
|
393
|
+
strings?: boolean;
|
|
394
|
+
numbers?: boolean;
|
|
395
|
+
};
|
|
396
|
+
/**
|
|
397
|
+
* Validator for `format: uuid` properties.
|
|
398
|
+
* - `'uuid'`: `z.uuid()`. Standard RFC 4122.
|
|
399
|
+
* - `'guid'`: `z.guid()`. Accepts Microsoft-style GUIDs.
|
|
400
|
+
*
|
|
401
|
+
* @default 'uuid'
|
|
402
|
+
*/
|
|
403
|
+
guidType?: 'uuid' | 'guid';
|
|
404
|
+
/**
|
|
405
|
+
* Output form for an OpenAPI `pattern` inside `.regex(...)`.
|
|
406
|
+
* - `'literal'`: a regex literal, `.regex(/^[a-z]+$/)`.
|
|
407
|
+
* - `'constructor'`: the `RegExp` constructor, `.regex(new RegExp("^[a-z]+$"))`.
|
|
408
|
+
*
|
|
409
|
+
* @default 'literal'
|
|
410
|
+
*/
|
|
411
|
+
regexType?: 'literal' | 'constructor';
|
|
412
|
+
/**
|
|
413
|
+
* Wrap generated schemas with `z.compile(...)` to enable Zod's hyperoptimized
|
|
414
|
+
* fast-path validation logic.
|
|
415
|
+
*
|
|
416
|
+
* Set to `true` or pass `{ strict: true }` to enforce that schemas compile into
|
|
417
|
+
* flat JavaScript without silently degrading to the standard interpreter.
|
|
418
|
+
*
|
|
419
|
+
* @default false
|
|
420
|
+
* @note Only compatible with Zod v4.5.0 or above.
|
|
421
|
+
* @see https://zod.dev/blog/introducing-z-compile
|
|
422
|
+
*/
|
|
423
|
+
compile?: boolean | CompileOptions;
|
|
424
|
+
/**
|
|
425
|
+
* Switch to Zod Mini's functional API for better tree-shaking. Also defaults
|
|
426
|
+
* `importPath` to `'zod/mini'`.
|
|
427
|
+
*
|
|
428
|
+
* @default false
|
|
429
|
+
* @beta
|
|
430
|
+
*/
|
|
431
|
+
mini?: boolean;
|
|
432
|
+
/**
|
|
433
|
+
* Override how schema and operation names are built. Methods you omit fall back
|
|
434
|
+
* to the default `resolverZod`.
|
|
435
|
+
*/
|
|
436
|
+
resolver?: ResolverPatch<ResolverZod>;
|
|
437
|
+
/**
|
|
438
|
+
* Generate TypeScript type guards (`is*`) and assertion functions (`assert*`) for schemas
|
|
439
|
+
* using Zod v4's native `validate` API.
|
|
440
|
+
* - `true`: Generates both `is*` type guards and `assert*` assertion functions.
|
|
441
|
+
* - `{ is?: boolean; assert?: boolean }`: Selectively enable type guards or assertions.
|
|
442
|
+
*
|
|
443
|
+
* @default false
|
|
444
|
+
* @note Only compatible with Zod v4.6.0 or above.
|
|
445
|
+
* @see https://zod.dev
|
|
446
|
+
*/
|
|
447
|
+
typeGuards?: boolean | {
|
|
448
|
+
is?: boolean;
|
|
449
|
+
assert?: boolean;
|
|
450
|
+
};
|
|
451
|
+
/**
|
|
452
|
+
* Replace the Zod handler for a specific schema type (`'integer'`, `'date'`, ...).
|
|
453
|
+
* When `mini: true`, overrides target the Zod Mini printer instead.
|
|
454
|
+
*
|
|
455
|
+
* A handler that returns a different expression per `this.options.direction` declares a two-way
|
|
456
|
+
* conversion, such as a `time` field carried as an ISO string but modeled as a
|
|
457
|
+
* `Temporal.PlainTime`. The generator then emits an `${name}InputSchema` variant for request
|
|
458
|
+
* bodies to resolve to, `$ref` included. Ignore `direction` and only the printed output changes.
|
|
459
|
+
*/
|
|
460
|
+
printer?: {
|
|
461
|
+
nodes?: PrinterZodNodes | PrinterZodMiniNodes;
|
|
462
|
+
};
|
|
463
|
+
/**
|
|
464
|
+
* Macros applied to each schema or operation node before printing.
|
|
465
|
+
*/
|
|
466
|
+
macros?: Array<ast.Macro>;
|
|
467
|
+
};
|
|
468
|
+
type ResolvedOptions = {
|
|
469
|
+
output: Output;
|
|
470
|
+
exclude: Array<Exclude>;
|
|
471
|
+
include: Array<Include> | undefined;
|
|
472
|
+
override: Array<Override<ResolvedOptions>>;
|
|
473
|
+
group: Group | null;
|
|
474
|
+
inferred: NonNullable<Options['inferred']>;
|
|
475
|
+
importPath: NonNullable<Options['importPath']>;
|
|
476
|
+
coercion: NonNullable<Options['coercion']>;
|
|
477
|
+
guidType: NonNullable<Options['guidType']>;
|
|
478
|
+
regexType: NonNullable<Options['regexType']>;
|
|
479
|
+
compile: NonNullable<Options['compile']>;
|
|
480
|
+
mini: NonNullable<Options['mini']>;
|
|
481
|
+
typeGuards: NonNullable<Options['typeGuards']>;
|
|
482
|
+
printer: Options['printer'];
|
|
483
|
+
};
|
|
484
|
+
type PluginZod = PluginType<'plugin-zod', Options, ResolvedOptions, ResolverZod>;
|
|
485
|
+
declare global {
|
|
486
|
+
namespace Kubb {
|
|
487
|
+
interface PluginRegistry {
|
|
488
|
+
'plugin-zod': PluginZod;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
//#endregion
|
|
493
|
+
//#region src/generators/zodGenerator.d.ts
|
|
494
|
+
/**
|
|
495
|
+
* Built-in generator for `@kubb/plugin-zod`. Emits one Zod schema per
|
|
496
|
+
* schema in the spec plus per-operation request/response/parameter schemas.
|
|
497
|
+
* When `mini: true`, schemas use the Zod Mini functional API instead of
|
|
498
|
+
* chainable methods.
|
|
499
|
+
*/
|
|
500
|
+
export declare const zodGenerator: import("kubb/kit").Generator<PluginZod, unknown>;
|
|
501
|
+
//#endregion
|
|
502
|
+
//#region src/plugin.d.ts
|
|
503
|
+
/**
|
|
504
|
+
* Canonical plugin name for `@kubb/plugin-zod`. Used for driver lookups and
|
|
505
|
+
* cross-plugin dependency references.
|
|
506
|
+
*/
|
|
507
|
+
export declare const pluginZodName = "plugin-zod";
|
|
508
|
+
/**
|
|
509
|
+
* Generates Zod v4 schemas from an OpenAPI spec. Use them to validate API
|
|
510
|
+
* responses at runtime, build form schemas, or feed back into router libraries
|
|
511
|
+
* that consume Zod (tRPC, Hono, Elysia). Pair with `@kubb/plugin-axios` or
|
|
512
|
+
* `@kubb/plugin-fetch` and set the client's `validator: 'zod'` to validate every response
|
|
513
|
+
* automatically.
|
|
514
|
+
*
|
|
515
|
+
* @example
|
|
516
|
+
* ```ts
|
|
517
|
+
* import { defineConfig } from 'kubb/config'
|
|
518
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
519
|
+
* import { pluginZod } from '@kubb/plugin-zod'
|
|
520
|
+
*
|
|
521
|
+
* export default defineConfig({
|
|
522
|
+
* input: './petStore.yaml',
|
|
523
|
+
* output: { path: './src/gen' },
|
|
524
|
+
* plugins: [
|
|
525
|
+
* pluginTs(),
|
|
526
|
+
* pluginZod({
|
|
527
|
+
* output: { path: './zod' },
|
|
528
|
+
* inferred: true,
|
|
529
|
+
* }),
|
|
530
|
+
* ],
|
|
531
|
+
* })
|
|
532
|
+
* ```
|
|
533
|
+
*/
|
|
534
|
+
export declare const pluginZod: import("kubb/kit").PluginFactory<PluginZod>;
|
|
535
|
+
//#endregion
|
|
536
|
+
//#region src/resolvers/resolverZod.d.ts
|
|
537
|
+
/**
|
|
538
|
+
* Default resolver used by `@kubb/plugin-zod`. Decides the names and file
|
|
539
|
+
* paths for every generated Zod schema. Schemas use camelCase with a
|
|
540
|
+
* `Schema` suffix (`listPetsSchema`); their inferred types use PascalCase
|
|
541
|
+
* with a `SchemaType` suffix (`PetSchemaType`), so the value and the type
|
|
542
|
+
* never share an identifier even when the schema name is all-uppercase.
|
|
543
|
+
*
|
|
544
|
+
* @example Resolve schema and type names
|
|
545
|
+
* ```ts
|
|
546
|
+
* import { resolverZod } from '@kubb/plugin-zod'
|
|
547
|
+
*
|
|
548
|
+
* resolverZod.name('list pets') // 'listPetsSchema'
|
|
549
|
+
* resolverZod.schema.typeName('pet') // 'PetSchemaType'
|
|
550
|
+
* ```
|
|
551
|
+
*/
|
|
552
|
+
export declare const resolverZod: ResolverZod;
|
|
553
|
+
//#endregion
|
|
554
|
+
export { type CompileOptions, type PluginZod, type PrinterZodFactory, type PrinterZodMiniFactory, type PrinterZodMiniNodes, type PrinterZodMiniOptions, type PrinterZodNodes, type PrinterZodOptions, type ResolverZod, pluginZod as default };
|
|
555
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
1
|
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
3
|
-
import { AdapterOas } from "@kubb/adapter-oas";
|
|
4
2
|
//#region src/printers/printerZod.d.ts
|
|
5
3
|
/**
|
|
6
4
|
* Partial map of node-type overrides for the Zod printer.
|
|
@@ -58,7 +56,7 @@ type PrinterZodOptions = {
|
|
|
58
56
|
/**
|
|
59
57
|
* Date format in the OpenAPI spec (`'date'` or `'date-time'`).
|
|
60
58
|
*/
|
|
61
|
-
dateType?:
|
|
59
|
+
dateType?: ast.ParserOptions['dateType'];
|
|
62
60
|
/**
|
|
63
61
|
* Transforms raw schema names into valid JavaScript identifiers.
|
|
64
62
|
*/
|