@kubb/plugin-zod 5.0.0-beta.10 → 5.0.0-beta.100
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 +22 -25
- package/dist/index.cjs +1454 -605
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +255 -144
- package/dist/index.js +1442 -593
- package/dist/index.js.map +1 -1
- package/package.json +8 -23
- package/extension.yaml +0 -485
- package/src/components/Operations.tsx +0 -77
- package/src/components/Zod.tsx +0 -42
- package/src/constants.ts +0 -5
- package/src/generators/zodGenerator.tsx +0 -216
- package/src/index.ts +0 -11
- package/src/plugin.ts +0 -94
- package/src/printers/printerZod.ts +0 -365
- package/src/printers/printerZodMini.ts +0 -310
- package/src/resolvers/resolverZod.ts +0 -57
- package/src/types.ts +0 -187
- package/src/utils.ts +0 -222
- /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { t as __name } from "./
|
|
2
|
-
import
|
|
3
|
-
import { Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
|
|
1
|
+
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
+
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
4
3
|
import { AdapterOas } from "@kubb/adapter-oas";
|
|
5
|
-
|
|
6
4
|
//#region src/printers/printerZod.d.ts
|
|
7
5
|
/**
|
|
8
6
|
* Partial map of node-type overrides for the Zod printer.
|
|
9
7
|
*
|
|
10
8
|
* Each key is a `SchemaType` string (e.g. `'date'`, `'string'`). The function
|
|
11
9
|
* replaces the built-in handler for that node type. Use `this.transform` to
|
|
12
|
-
* recurse into nested schema nodes,
|
|
10
|
+
* recurse into nested schema nodes, `this.base` to reuse the output of the
|
|
11
|
+
* handler being replaced, and `this.options` to read printer options.
|
|
13
12
|
*
|
|
14
13
|
* @example Override the `date` handler
|
|
15
14
|
* ```ts
|
|
@@ -17,7 +16,20 @@ import { AdapterOas } from "@kubb/adapter-oas";
|
|
|
17
16
|
* printer: {
|
|
18
17
|
* nodes: {
|
|
19
18
|
* date(node) {
|
|
20
|
-
* return 'z.
|
|
19
|
+
* return 'z.iso.date()'
|
|
20
|
+
* },
|
|
21
|
+
* },
|
|
22
|
+
* },
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example Wrap the built-in output
|
|
27
|
+
* ```ts
|
|
28
|
+
* pluginZod({
|
|
29
|
+
* printer: {
|
|
30
|
+
* nodes: {
|
|
31
|
+
* object(node) {
|
|
32
|
+
* return `${this.base(node)}.openapi(${JSON.stringify({ description: node.description })})`
|
|
21
33
|
* },
|
|
22
34
|
* },
|
|
23
35
|
* },
|
|
@@ -37,13 +49,16 @@ type PrinterZodOptions = {
|
|
|
37
49
|
*/
|
|
38
50
|
guidType?: PluginZod['resolvedOptions']['guidType'];
|
|
39
51
|
/**
|
|
40
|
-
*
|
|
52
|
+
* Output form for an OpenAPI `pattern` inside `.regex(...)`: a regex literal
|
|
53
|
+
* (`'literal'`) or the `RegExp` constructor (`'constructor'`).
|
|
54
|
+
*
|
|
55
|
+
* @default 'literal'
|
|
41
56
|
*/
|
|
42
|
-
|
|
57
|
+
regexType?: PluginZod['resolvedOptions']['regexType'];
|
|
43
58
|
/**
|
|
44
|
-
*
|
|
59
|
+
* Date format in the OpenAPI spec (`'date'` or `'date-time'`).
|
|
45
60
|
*/
|
|
46
|
-
|
|
61
|
+
dateType?: AdapterOas['resolvedOptions']['dateType'];
|
|
47
62
|
/**
|
|
48
63
|
* Transforms raw schema names into valid JavaScript identifiers.
|
|
49
64
|
*/
|
|
@@ -51,12 +66,21 @@ type PrinterZodOptions = {
|
|
|
51
66
|
/**
|
|
52
67
|
* Properties to exclude using `.omit({ key: true })`.
|
|
53
68
|
*/
|
|
54
|
-
keysToOmit?: Array<string
|
|
69
|
+
keysToOmit?: Array<string> | null;
|
|
55
70
|
/**
|
|
56
71
|
* Schema names that form circular dependency chains.
|
|
57
72
|
* Properties referencing these emit lazy getters wrapping refs in `z.lazy(() => …)`.
|
|
58
73
|
*/
|
|
59
74
|
cyclicSchemas?: ReadonlySet<string>;
|
|
75
|
+
/**
|
|
76
|
+
* Print direction for `dateType: 'date'` fields (`Date` in TypeScript):
|
|
77
|
+
* - `'output'` (default): decode the wire `string` into a `Date` (response bodies).
|
|
78
|
+
* - `'input'`: encode a `Date` back into the wire `string` (request bodies/params).
|
|
79
|
+
*
|
|
80
|
+
* Diverging the directions requires the generator to emit an `${name}InputSchema`
|
|
81
|
+
* variant for each date-bearing component.
|
|
82
|
+
*/
|
|
83
|
+
direction?: 'input' | 'output';
|
|
60
84
|
/**
|
|
61
85
|
* Custom handler map for node type overrides.
|
|
62
86
|
*/
|
|
@@ -86,7 +110,8 @@ declare const printerZod: (options?: PrinterZodOptions | undefined) => ast.Print
|
|
|
86
110
|
*
|
|
87
111
|
* Each key is a `SchemaType` string (e.g. `'date'`, `'string'`). The function
|
|
88
112
|
* replaces the built-in handler for that node type. Use `this.transform` to
|
|
89
|
-
* recurse into nested schema nodes,
|
|
113
|
+
* recurse into nested schema nodes, `this.base` to reuse the output of the
|
|
114
|
+
* handler being replaced, and `this.options` to read printer options.
|
|
90
115
|
*
|
|
91
116
|
* @example Override the `date` handler
|
|
92
117
|
* ```ts
|
|
@@ -111,9 +136,12 @@ type PrinterZodMiniOptions = {
|
|
|
111
136
|
*/
|
|
112
137
|
guidType?: PluginZod['resolvedOptions']['guidType'];
|
|
113
138
|
/**
|
|
114
|
-
*
|
|
139
|
+
* Output form for an OpenAPI `pattern` inside `z.regex(...)`: a regex literal
|
|
140
|
+
* (`'literal'`) or the `RegExp` constructor (`'constructor'`).
|
|
141
|
+
*
|
|
142
|
+
* @default 'literal'
|
|
115
143
|
*/
|
|
116
|
-
|
|
144
|
+
regexType?: PluginZod['resolvedOptions']['regexType'];
|
|
117
145
|
/**
|
|
118
146
|
* Transforms raw schema names into valid JavaScript identifiers.
|
|
119
147
|
*/
|
|
@@ -121,7 +149,7 @@ type PrinterZodMiniOptions = {
|
|
|
121
149
|
/**
|
|
122
150
|
* Properties to exclude using `.omit({ key: true })`.
|
|
123
151
|
*/
|
|
124
|
-
keysToOmit?: Array<string
|
|
152
|
+
keysToOmit?: Array<string> | null;
|
|
125
153
|
/**
|
|
126
154
|
* Schema names that form circular dependency chains.
|
|
127
155
|
* Properties referencing these emit lazy getters wrapping refs in `z.lazy(() => …)`.
|
|
@@ -137,7 +165,7 @@ type PrinterZodMiniOptions = {
|
|
|
137
165
|
*/
|
|
138
166
|
type PrinterZodMiniFactory = ast.PrinterFactoryOptions<'zod-mini', PrinterZodMiniOptions, string, string>;
|
|
139
167
|
/**
|
|
140
|
-
* Zod v4
|
|
168
|
+
* Zod v4 Mini printer built with `definePrinter`.
|
|
141
169
|
*
|
|
142
170
|
* Converts a `SchemaNode` AST into a Zod v4 code string using the functional API
|
|
143
171
|
* (`z.optional(z.string())`) for improved tree-shaking. See {@link printerZod} for the chainable API.
|
|
@@ -153,110 +181,176 @@ declare const printerZodMini: (options?: PrinterZodMiniOptions | undefined) => a
|
|
|
153
181
|
//#region src/types.d.ts
|
|
154
182
|
/**
|
|
155
183
|
* Resolver for Zod that provides naming methods for schema types.
|
|
184
|
+
*
|
|
185
|
+
* The top-level `name` resolves a camelCase schema function name with a `Schema` suffix
|
|
186
|
+
* (`listPetsSchema`), and `file` casts generated file names the same way. Composite naming lives in
|
|
187
|
+
* the `schema`, `param`, and `response` namespaces.
|
|
156
188
|
*/
|
|
157
|
-
type ResolverZod = Resolver &
|
|
158
|
-
/**
|
|
159
|
-
*
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
resolveResponsesName(this: ResolverZod, node: ast.OperationNode): string;
|
|
194
|
-
/**
|
|
195
|
-
* Resolves the name for the union of all operation responses.
|
|
196
|
-
*
|
|
197
|
-
* @example Response union names
|
|
198
|
-
* `resolver.resolveResponseName(node) // → 'listPetsResponseSchema'`
|
|
199
|
-
*/
|
|
200
|
-
resolveResponseName(this: ResolverZod, node: ast.OperationNode): string;
|
|
201
|
-
/**
|
|
202
|
-
* Resolves the name for an operation's grouped path parameters type.
|
|
203
|
-
*
|
|
204
|
-
* @example Path parameters names
|
|
205
|
-
* `resolver.resolvePathParamsName(node, param) // → 'deletePetPathPetIdSchema'`
|
|
206
|
-
*/
|
|
207
|
-
resolvePathParamsName(this: ResolverZod, node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
189
|
+
type ResolverZod = Resolver & {
|
|
190
|
+
/**
|
|
191
|
+
* Names derived from a component schema: its inferred types and the request (input) direction
|
|
192
|
+
* variant, where a date-bearing component encodes `Date` back to a wire `string`.
|
|
193
|
+
*/
|
|
194
|
+
schema: {
|
|
195
|
+
/**
|
|
196
|
+
* Resolves the schema type name (inferred type from schema).
|
|
197
|
+
*
|
|
198
|
+
* @example Schema type names
|
|
199
|
+
* `resolver.schema.typeName('pet') // → 'PetSchemaType'`
|
|
200
|
+
*/
|
|
201
|
+
typeName(name: string): string;
|
|
202
|
+
/**
|
|
203
|
+
* Resolves the generated type name from the schema.
|
|
204
|
+
*
|
|
205
|
+
* @example Type names
|
|
206
|
+
* `resolver.schema.type('petSchema') // → 'PetSchemaType'`
|
|
207
|
+
*/
|
|
208
|
+
type(name: string): string;
|
|
209
|
+
/**
|
|
210
|
+
* Resolves the schema function name for the request (input) direction of a
|
|
211
|
+
* date-bearing component, where `Date` is encoded back to a wire `string`.
|
|
212
|
+
*
|
|
213
|
+
* @example Input schema names
|
|
214
|
+
* `resolver.schema.inputName('order') // → 'orderInputSchema'`
|
|
215
|
+
*/
|
|
216
|
+
inputName(name: string): string;
|
|
217
|
+
/**
|
|
218
|
+
* Resolves the inferred type name for the request (input) direction variant.
|
|
219
|
+
*
|
|
220
|
+
* @example Input schema type names
|
|
221
|
+
* `resolver.schema.inputTypeName('order') // → 'OrderInputSchemaType'`
|
|
222
|
+
*/
|
|
223
|
+
inputTypeName(name: string): string;
|
|
224
|
+
};
|
|
208
225
|
/**
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
226
|
+
* Names for an operation's parameters: an individual parameter and the grouped path, query, and
|
|
227
|
+
* header schemas.
|
|
228
|
+
*/
|
|
229
|
+
param: {
|
|
230
|
+
/**
|
|
231
|
+
* Resolves the schema name for an individual parameter.
|
|
232
|
+
*
|
|
233
|
+
* @example Individual parameter name
|
|
234
|
+
* `resolver.param.name(node, param) // → 'deletePetPathPetIdSchema'`
|
|
235
|
+
*/
|
|
236
|
+
name(node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
237
|
+
/**
|
|
238
|
+
* Resolves the name for an operation's grouped path parameters schema.
|
|
239
|
+
*
|
|
240
|
+
* @example Path parameters names
|
|
241
|
+
* `resolver.param.path(node, param) // → 'deletePetPathSchema'`
|
|
242
|
+
*/
|
|
243
|
+
path(node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
244
|
+
/**
|
|
245
|
+
* Resolves the name for an operation's grouped query parameters schema.
|
|
246
|
+
*
|
|
247
|
+
* @example Query parameters names
|
|
248
|
+
* `resolver.param.query(node, param) // → 'findPetsByStatusQuerySchema'`
|
|
249
|
+
*/
|
|
250
|
+
query(node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
251
|
+
/**
|
|
252
|
+
* Resolves the name for an operation's grouped header parameters schema.
|
|
253
|
+
*
|
|
254
|
+
* @example Header parameters names
|
|
255
|
+
* `resolver.param.headers(node, param) // → 'deletePetHeadersSchema'`
|
|
256
|
+
*/
|
|
257
|
+
headers(node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
258
|
+
};
|
|
215
259
|
/**
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
260
|
+
* Names for an operation's responses: per-status schemas, the request body, and the combined,
|
|
261
|
+
* union, and error names.
|
|
262
|
+
*/
|
|
263
|
+
response: {
|
|
264
|
+
/**
|
|
265
|
+
* Resolves the name for an operation response by status code.
|
|
266
|
+
*
|
|
267
|
+
* @example Response status names
|
|
268
|
+
* `resolver.response.status(node, 200) // → 'listPetsStatus200Schema'`
|
|
269
|
+
*/
|
|
270
|
+
status(node: ast.OperationNode, statusCode: ast.StatusCode): string;
|
|
271
|
+
/**
|
|
272
|
+
* Resolves the request body schema name.
|
|
273
|
+
*
|
|
274
|
+
* @example Request body names
|
|
275
|
+
* `resolver.response.body(node) // → 'createPetBodySchema'`
|
|
276
|
+
*/
|
|
277
|
+
body(node: ast.OperationNode): string;
|
|
278
|
+
/**
|
|
279
|
+
* Resolves the name for the collection of all operation responses.
|
|
280
|
+
*
|
|
281
|
+
* @example Responses collection names
|
|
282
|
+
* `resolver.response.responses(node) // → 'listPetsResponsesSchema'`
|
|
283
|
+
*/
|
|
284
|
+
responses(node: ast.OperationNode): string;
|
|
285
|
+
/**
|
|
286
|
+
* Resolves the name for the union of all operation responses.
|
|
287
|
+
*
|
|
288
|
+
* @example Response union names
|
|
289
|
+
* `resolver.response.response(node) // → 'listPetsResponseSchema'`
|
|
290
|
+
*/
|
|
291
|
+
response(node: ast.OperationNode): string;
|
|
292
|
+
/**
|
|
293
|
+
* Resolves the name for the union of an operation's error (non-2xx) responses. Generated clients
|
|
294
|
+
* validate the error body against this on the non-throw path.
|
|
295
|
+
*
|
|
296
|
+
* @example Error union names
|
|
297
|
+
* `resolver.response.error(node) // → 'listPetsErrorSchema'`
|
|
298
|
+
*/
|
|
299
|
+
error(node: ast.OperationNode): string;
|
|
300
|
+
/**
|
|
301
|
+
* Resolves the inferred type name for an operation's combined `{ body, path, query, headers }`
|
|
302
|
+
* options object. Only meaningful when `inferred: true`, since the schema and type this name
|
|
303
|
+
* points to are generated only in that case.
|
|
304
|
+
*
|
|
305
|
+
* @example Options type names
|
|
306
|
+
* `resolver.response.options(node) // → 'ListPetsOptionsSchemaType'`
|
|
307
|
+
*/
|
|
308
|
+
options(node: ast.OperationNode): string;
|
|
309
|
+
};
|
|
222
310
|
};
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
*/
|
|
231
|
-
group?: Group;
|
|
311
|
+
/**
|
|
312
|
+
* Where the generated Zod schemas are written and how they are exported, plus the optional
|
|
313
|
+
* `group` strategy. The `group` option organizes `output.mode: 'directory'` output into per-tag or per-path subdirectories.
|
|
314
|
+
*
|
|
315
|
+
* @default { path: 'zod', barrel: { type: 'named' } }
|
|
316
|
+
*/
|
|
317
|
+
type Options = OutputOptions & {
|
|
232
318
|
/**
|
|
233
|
-
*
|
|
319
|
+
* Skip operations matching at least one entry in the list.
|
|
234
320
|
*/
|
|
235
321
|
exclude?: Array<Exclude>;
|
|
236
322
|
/**
|
|
237
|
-
*
|
|
323
|
+
* Restrict generation to operations matching at least one entry in the list.
|
|
238
324
|
*/
|
|
239
325
|
include?: Array<Include>;
|
|
240
326
|
/**
|
|
241
|
-
*
|
|
327
|
+
* Apply a different options object to operations matching a pattern.
|
|
242
328
|
*/
|
|
243
329
|
override?: Array<Override<ResolvedOptions>>;
|
|
244
330
|
/**
|
|
245
|
-
*
|
|
331
|
+
* Module specifier used in the `import { z } from '...'` statement.
|
|
332
|
+
* Use `'zod/mini'` for the tree-shakeable bundle.
|
|
246
333
|
*
|
|
247
|
-
* @default 'zod'
|
|
334
|
+
* @default mini ? 'zod/mini' : 'zod'
|
|
248
335
|
*/
|
|
249
336
|
importPath?: 'zod' | 'zod/mini' | (string & {});
|
|
250
337
|
/**
|
|
251
|
-
*
|
|
252
|
-
|
|
253
|
-
typed?: boolean;
|
|
254
|
-
/**
|
|
255
|
-
* Return schemas as inferred types using `z.infer`.
|
|
338
|
+
* Export a `z.infer<typeof schema>` type alias next to every generated schema.
|
|
339
|
+
* Lets the Zod schema act as the single source of truth.
|
|
256
340
|
*/
|
|
257
341
|
inferred?: boolean;
|
|
258
342
|
/**
|
|
259
|
-
*
|
|
343
|
+
* Wrap schemas in `z.coerce` so input is coerced before validation. Useful for
|
|
344
|
+
* form data and query params where everything arrives as a string.
|
|
345
|
+
* - `true` coerces strings, numbers, and dates.
|
|
346
|
+
* - Object form picks per-primitive coercion.
|
|
347
|
+
*
|
|
348
|
+
* `dates` applies to fields typed as `Date` (adapter `dateType: 'date'`): they
|
|
349
|
+
* validate with `z.coerce.date()` instead of the string-to-Date codec. Fields
|
|
350
|
+
* kept as ISO strings (`z.iso.date()`, `z.iso.datetime()`) are never coerced.
|
|
351
|
+
*
|
|
352
|
+
* @default false
|
|
353
|
+
* @see https://zod.dev/?id=coercion-for-primitives
|
|
260
354
|
*/
|
|
261
355
|
coercion?: boolean | {
|
|
262
356
|
dates?: boolean;
|
|
@@ -264,68 +358,58 @@ type Options = {
|
|
|
264
358
|
numbers?: boolean;
|
|
265
359
|
};
|
|
266
360
|
/**
|
|
267
|
-
*
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Validator to use for UUID format: `uuid` or `guid`.
|
|
361
|
+
* Validator for `format: uuid` properties.
|
|
362
|
+
* - `'uuid'`: `z.uuid()`. Standard RFC 4122.
|
|
363
|
+
* - `'guid'`: `z.guid()`. Accepts Microsoft-style GUIDs.
|
|
272
364
|
*
|
|
273
365
|
* @default 'uuid'
|
|
274
366
|
*/
|
|
275
367
|
guidType?: 'uuid' | 'guid';
|
|
276
368
|
/**
|
|
277
|
-
*
|
|
369
|
+
* Output form for an OpenAPI `pattern` inside `.regex(...)`.
|
|
370
|
+
* - `'literal'`: a regex literal, `.regex(/^[a-z]+$/)`.
|
|
371
|
+
* - `'constructor'`: the `RegExp` constructor, `.regex(new RegExp("^[a-z]+$"))`.
|
|
278
372
|
*
|
|
279
|
-
* @default
|
|
373
|
+
* @default 'literal'
|
|
280
374
|
*/
|
|
281
|
-
|
|
375
|
+
regexType?: 'literal' | 'constructor';
|
|
282
376
|
/**
|
|
283
|
-
*
|
|
377
|
+
* Switch to Zod Mini's functional API for better tree-shaking. Also defaults
|
|
378
|
+
* `importPath` to `'zod/mini'`.
|
|
284
379
|
*
|
|
285
|
-
*
|
|
286
|
-
|
|
287
|
-
wrapOutput?: (arg: {
|
|
288
|
-
output: string;
|
|
289
|
-
schema: ast.SchemaNode;
|
|
290
|
-
}) => string | undefined;
|
|
291
|
-
/**
|
|
292
|
-
* Apply casing to parameter names.
|
|
293
|
-
*/
|
|
294
|
-
paramsCasing?: 'camelcase';
|
|
295
|
-
/**
|
|
296
|
-
* Additional generators alongside the default generators.
|
|
380
|
+
* @default false
|
|
381
|
+
* @beta
|
|
297
382
|
*/
|
|
298
|
-
|
|
383
|
+
mini?: boolean;
|
|
299
384
|
/**
|
|
300
|
-
* Override
|
|
385
|
+
* Override how schema and operation names are built. Methods you omit fall back
|
|
386
|
+
* to the default `resolverZod`.
|
|
301
387
|
*/
|
|
302
|
-
resolver?:
|
|
388
|
+
resolver?: ResolverPatch<ResolverZod>;
|
|
303
389
|
/**
|
|
304
|
-
*
|
|
390
|
+
* Replace the Zod handler for a specific schema type (`'integer'`, `'date'`, ...).
|
|
391
|
+
* When `mini: true`, overrides target the Zod Mini printer instead.
|
|
305
392
|
*/
|
|
306
393
|
printer?: {
|
|
307
394
|
nodes?: PrinterZodNodes | PrinterZodMiniNodes;
|
|
308
395
|
};
|
|
309
396
|
/**
|
|
310
|
-
*
|
|
397
|
+
* Macros applied to each schema or operation node before printing.
|
|
311
398
|
*/
|
|
312
|
-
|
|
399
|
+
macros?: Array<ast.Macro>;
|
|
313
400
|
};
|
|
314
401
|
type ResolvedOptions = {
|
|
315
402
|
output: Output;
|
|
316
403
|
exclude: Array<Exclude>;
|
|
317
404
|
include: Array<Include> | undefined;
|
|
318
405
|
override: Array<Override<ResolvedOptions>>;
|
|
319
|
-
group: Group |
|
|
320
|
-
typed: NonNullable<Options['typed']>;
|
|
406
|
+
group: Group | null;
|
|
321
407
|
inferred: NonNullable<Options['inferred']>;
|
|
322
408
|
importPath: NonNullable<Options['importPath']>;
|
|
323
409
|
coercion: NonNullable<Options['coercion']>;
|
|
324
|
-
operations: NonNullable<Options['operations']>;
|
|
325
410
|
guidType: NonNullable<Options['guidType']>;
|
|
411
|
+
regexType: NonNullable<Options['regexType']>;
|
|
326
412
|
mini: NonNullable<Options['mini']>;
|
|
327
|
-
wrapOutput: Options['wrapOutput'];
|
|
328
|
-
paramsCasing: Options['paramsCasing'];
|
|
329
413
|
printer: Options['printer'];
|
|
330
414
|
};
|
|
331
415
|
type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, ResolverZod>;
|
|
@@ -338,36 +422,63 @@ declare global {
|
|
|
338
422
|
}
|
|
339
423
|
//#endregion
|
|
340
424
|
//#region src/generators/zodGenerator.d.ts
|
|
341
|
-
|
|
425
|
+
/**
|
|
426
|
+
* Built-in generator for `@kubb/plugin-zod`. Emits one Zod schema per
|
|
427
|
+
* schema in the spec plus per-operation request/response/parameter schemas.
|
|
428
|
+
* When `mini: true`, schemas use the Zod Mini functional API instead of
|
|
429
|
+
* chainable methods.
|
|
430
|
+
*/
|
|
431
|
+
declare const zodGenerator: import("kubb/kit").Generator<PluginZod, unknown>;
|
|
342
432
|
//#endregion
|
|
343
433
|
//#region src/plugin.d.ts
|
|
344
434
|
/**
|
|
345
|
-
* Canonical plugin name for `@kubb/plugin-zod
|
|
435
|
+
* Canonical plugin name for `@kubb/plugin-zod`. Used for driver lookups and
|
|
436
|
+
* cross-plugin dependency references.
|
|
346
437
|
*/
|
|
347
438
|
declare const pluginZodName = "plugin-zod";
|
|
348
439
|
/**
|
|
349
|
-
* Generates Zod
|
|
350
|
-
*
|
|
351
|
-
*
|
|
440
|
+
* Generates Zod v4 schemas from an OpenAPI spec. Use them to validate API
|
|
441
|
+
* responses at runtime, build form schemas, or feed back into router libraries
|
|
442
|
+
* that consume Zod (tRPC, Hono, Elysia). Pair with `@kubb/plugin-axios` or
|
|
443
|
+
* `@kubb/plugin-fetch` and set the client's `validator: 'zod'` to validate every response
|
|
444
|
+
* automatically.
|
|
352
445
|
*
|
|
353
|
-
* @example
|
|
446
|
+
* @example
|
|
354
447
|
* ```ts
|
|
355
|
-
* import
|
|
448
|
+
* import { defineConfig } from 'kubb/config'
|
|
449
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
450
|
+
* import { pluginZod } from '@kubb/plugin-zod'
|
|
451
|
+
*
|
|
356
452
|
* export default defineConfig({
|
|
357
|
-
*
|
|
453
|
+
* input: './petStore.yaml',
|
|
454
|
+
* output: { path: './src/gen' },
|
|
455
|
+
* plugins: [
|
|
456
|
+
* pluginTs(),
|
|
457
|
+
* pluginZod({
|
|
458
|
+
* output: { path: './zod' },
|
|
459
|
+
* inferred: true,
|
|
460
|
+
* }),
|
|
461
|
+
* ],
|
|
358
462
|
* })
|
|
359
463
|
* ```
|
|
360
464
|
*/
|
|
361
|
-
declare const pluginZod: (options?: Options | undefined) =>
|
|
465
|
+
declare const pluginZod: (options?: Options | undefined) => import("kubb/kit").Plugin<PluginZod>;
|
|
362
466
|
//#endregion
|
|
363
467
|
//#region src/resolvers/resolverZod.d.ts
|
|
364
468
|
/**
|
|
365
|
-
*
|
|
469
|
+
* Default resolver used by `@kubb/plugin-zod`. Decides the names and file
|
|
470
|
+
* paths for every generated Zod schema. Schemas use camelCase with a
|
|
471
|
+
* `Schema` suffix (`listPetsSchema`); their inferred types use PascalCase
|
|
472
|
+
* with a `SchemaType` suffix (`PetSchemaType`), so the value and the type
|
|
473
|
+
* never share an identifier even when the schema name is all-uppercase.
|
|
366
474
|
*
|
|
367
|
-
*
|
|
475
|
+
* @example Resolve schema and type names
|
|
476
|
+
* ```ts
|
|
477
|
+
* import { resolverZod } from '@kubb/plugin-zod'
|
|
368
478
|
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
479
|
+
* resolverZod.name('list pets') // 'listPetsSchema'
|
|
480
|
+
* resolverZod.schema.typeName('pet') // 'PetSchemaType'
|
|
481
|
+
* ```
|
|
371
482
|
*/
|
|
372
483
|
declare const resolverZod: ResolverZod;
|
|
373
484
|
//#endregion
|