@kubb/plugin-zod 5.9.0 → 5.9.1

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.
@@ -47,7 +47,7 @@ The `integer` handler controls `int32` fields separately. To change integer repr
47
47
 
48
48
  ## Remove descriptions
49
49
 
50
- Use the [description-removal macro](https://kubb.dev/extensions/kubb-labs/plugin-ts/guides/customization#remove-descriptions) with `pluginZod({ macros: [dropDescriptions] })`. Generated schemas omit description metadata.
50
+ Use the [description-removal macro](https://kubb.dev/extensions/kubb-labs/plugin-ts/guides/customization#remove-descriptions) with `pluginZod({ macros: [dropDescriptions] })`. Schemas omit their own `.describe()` calls. A `$ref` to a described component keeps one, such as `addPetBodySchema = petSchema.describe('A pet')` or the property `owner: ownerSchema.describe('An owner')`, because a macro does not visit the schema a `$ref` points to.
51
51
 
52
52
  ## Encode custom types
53
53
 
@@ -64,7 +64,7 @@ const nodes: PrinterZodNodes = {
64
64
  },
65
65
  }
66
66
 
67
- pluginZod({ inferred: true, printer: { nodes } })
67
+ pluginZod({ inferred: 'codec', printer: { nodes } })
68
68
  ```
69
69
 
70
70
  Use a runtime that provides `Temporal`, or add its polyfill through a generated import or banner. Match the OpenAPI format: `time`, `date`, and `date-time` use `time`, `date`, and `datetime` handlers.
@@ -82,9 +82,9 @@ export const slotInputSchema = z.object({
82
82
  ```
83
83
 
84
84
  > [!IMPORTANT]
85
- > Use `inferred: true` without `pluginTs` so the client types follow these conversions. Types from `pluginTs` describe the wire format.
85
+ > Use `inferred: 'codec'` so the client types follow these conversions. With `inferred: true`, a request type is the encoded string, not `Temporal.PlainTime`. Types from `pluginTs` describe the wire format.
86
86
 
87
- For built-in date conversion, set `dateType: 'date'` on the adapter. Generated response schemas convert ISO datetimes to `Date`. Request schemas convert them back with `toISOString()`.
87
+ For built-in date conversion, set `dateType: 'date'` on the adapter. Generated response schemas convert ISO datetimes to `Date`. Request schemas convert them back with `toISOString()`. With `mini: true`, both print a plain `z.date()` without the conversion.
88
88
 
89
89
  ## Import a custom codec
90
90
 
@@ -120,8 +120,9 @@ Generated files import `myCodec` from `my-codec/zod`. Leave `root` unset on this
120
120
  | `integer` | `z.int()` | `z.int()` | Coerces to `z.coerce.number().int()` when `coercion.numbers` is enabled |
121
121
  | `integer`, `format: int32` | `z.int32()` | `z.int32()` | 32-bit signed integer |
122
122
  | `integer`, `format: uint32` | `z.uint32()` | `z.uint32()` | 32-bit unsigned integer |
123
- | `integer`, `format: int64` | `z.bigint()` | `z.bigint()` | 64-bit integer |
124
- | `string`, `format: byte` / `base64` | `z.base64()` | `z.base64()` | Base64 string validation |
123
+ | `integer`, `format: int64` | `z.coerce.bigint()` | `z.coerce.bigint()` | 64-bit integer, always coerced because JSON holds a number |
124
+ | `string`, `format: base64` | `z.base64()` | `z.base64()` | Base64 string validation |
125
+ | `string`, `format: byte` / `binary` | `z.instanceof(Blob)` | `z.instanceof(Blob)` | Binary payload |
125
126
  | `string`, `format: base64url` | `z.base64url()` | `z.base64url()` | URL-safe base64 string validation |
126
127
  | `string`, `contentEncoding: base64` / `base64url` | `z.base64()` / `z.base64url()` | `z.base64()` / `z.base64url()` | Same checks as the formats. Other encodings stay `z.string()` |
127
128
  | `string`, JSON `contentMediaType` with `contentSchema` | `z.string().refine(...)` | `z.string().check(z.refine(...))` | The string must parse as JSON that passes the content schema. It stays a string |
package/docs/options.md CHANGED
@@ -76,7 +76,7 @@ export type PutEventBodySchemaType = z.input<typeof putEventBodySchema>
76
76
 
77
77
  Pair `'codec'` with `validator: { request: 'zod', params: 'zod' }` in [`@kubb/plugin-fetch`](https://kubb.dev/extensions/kubb-labs/plugin-fetch/options#validator) or [`@kubb/plugin-axios`](https://kubb.dev/extensions/kubb-labs/plugin-axios/options#validator). Without request validation, the client sends the domain value unencoded.
78
78
 
79
- It also writes a `ResponsesSchema` for each operation (one schema per status code) and its inferred type. [`@kubb/plugin-fetch`](https://kubb.dev/extensions/kubb-labs/plugin-fetch) and [`@kubb/plugin-axios`](https://kubb.dev/extensions/kubb-labs/plugin-axios) key their `RequestResult` on it when `@kubb/plugin-ts` is absent.
79
+ `inferred` also writes a `ResponsesSchema` for each operation (one schema per status code) and its inferred type. [`@kubb/plugin-fetch`](https://kubb.dev/extensions/kubb-labs/plugin-fetch) and [`@kubb/plugin-axios`](https://kubb.dev/extensions/kubb-labs/plugin-axios) key their `RequestResult` on it when `@kubb/plugin-ts` is absent.
80
80
 
81
81
  ### coercion
82
82
 
@@ -107,6 +107,8 @@ Chooses which primitives to coerce.
107
107
  > [!NOTE]
108
108
  > `numbers` also coerces an enum whose schema has a numeric `format`, such as `type: integer, format: int32`. Other enums are not coerced. When such an enum is the discriminator of a `oneOf`, the union prints as `z.union` instead of `z.discriminatedUnion`, which cannot read coerced values.
109
109
  >
110
+ > `strings` replaces the `base64`, `base64url`, `jwt`, `ulid`, `iban`, and `duration` validators with `z.coerce.string()`, so those formats are no longer checked. Fields with `format: email`, `uri`, `uuid`, `ipv4`, or `ipv6` keep their validator and are not coerced. `numbers` prints every integer as `z.coerce.number().int()`, which drops the `int32` and `uint32` range checks.
111
+ >
110
112
  > `dates` coerces only `Date`-typed fields (from `dateType: 'date'`). ISO-string fields are never coerced, and neither are `format: time` fields, because `new Date()` cannot parse a bare `HH:mm:ss`. For a time-of-day type such as `Temporal.PlainTime`, see [Encode custom types](https://kubb.dev/extensions/kubb-labs/plugin-zod/guides/customization#encode-custom-types).
111
113
 
112
114
  ### guidType
@@ -148,14 +150,14 @@ Emits a regex literal, such as `.regex(/^[a-z]+$/)`.
148
150
  :::
149
151
 
150
152
  :::field{name="'constructor'"}
151
- Emits the `RegExp` constructor, such as `.regex(new RegExp('^[a-z]+$'))`.
153
+ Emits the `RegExp` constructor, such as `.regex(new RegExp("^[a-z]+$"))`.
152
154
  :::
153
155
 
154
156
  ::
155
157
 
156
158
  ### oneOfType
157
159
 
158
- Controls how a `oneOf` is validated. Use `'xor'` when values may carry extra keys, or when members have no `required` keys.
160
+ Controls how a `oneOf` is validated. Use `'xor'` when values may carry extra keys. With `'xor'`, members need `required` keys that tell them apart. When every key is optional, an object matches several members and `z.xor` rejects it.
159
161
 
160
162
  | | |
161
163
  | -------- | ------------------ |
@@ -198,16 +200,19 @@ Compiles schemas using `z.compile(...)`.
198
200
  :::
199
201
 
200
202
  :::field{name="{ strict: true }"}
201
- Passes `{ strict: true }` to `z.compile(...)`, which throws when any part of the schema cannot be compiled into flat JavaScript instead of falling back to the interpreter.
203
+ Passes `{ strict: true }` to `z.compile(...)`. Zod then throws when a part of the schema cannot be compiled into flat JavaScript, where `true` falls back to the interpreter.
202
204
  :::
203
205
 
204
206
  ::
205
207
 
206
- Schemas with circular references (`z.lazy`) and bare `$ref` response aliases stay uncompiled to prevent runtime errors.
208
+ Schemas with circular references (`z.lazy`) and bare `$ref` response aliases stay uncompiled to prevent runtime errors. An alias that adds a description, such as `petSchema.describe('A pet')`, is compiled.
209
+
210
+ > [!NOTE]
211
+ > `z.compile` cannot compile `z.coerce` or `z.xor`. With `strict: true`, a schema that is one of them stays uncompiled, so the generated module loads without a `ZodCompileUnsupportedError`. The same goes for a union with such a member, and for a schema that reaches a circular one through a `$ref`. Every `format: int64` schema is coerced, and so is every schema that [`coercion`](#coercion) covers. An object or array that holds a coerced field is still compiled, and Zod runs that field on its interpreter. To compile an `int64` schema, set [`integerType: 'number'`](https://kubb.dev/extensions/kubb-labs/adapter-oas/options#integertype) on the adapter.
207
212
 
208
213
  ### mini
209
214
 
210
- Generates [Zod Mini](https://zod.dev/packages/mini) schemas. They use functions (`z.optional(z.string())`) instead of method chains (`z.string().optional()`), so bundlers can drop unused validators. Also sets the `importPath` default to `'zod/mini'`.
215
+ Generates [Zod Mini](https://zod.dev/packages/mini) schemas. They use functions (`z.optional(z.string())`) instead of method chains (`z.string().optional()`), so bundlers can drop unused validators. `mini` also sets the `importPath` default to `'zod/mini'`.
211
216
 
212
217
  | | |
213
218
  | -------- | --------- |
@@ -236,7 +241,7 @@ Generates both `is<Schema>` type guards and `assert<Schema>` assertion functions
236
241
  :::
237
242
 
238
243
  :::field{name="{ is?: boolean; assert?: boolean }"}
239
- Enables type guards or assertions separately.
244
+ Turns type guards or assertions off separately. Both default to `true`, so `{ assert: false }` generates only the `is*` guards.
240
245
  :::
241
246
 
242
247
  ::
@@ -284,6 +289,7 @@ type ResolverZodPatch = {
284
289
  path?(node: OperationNode, param: ParameterNode): string
285
290
  query?(node: OperationNode, param: ParameterNode): string
286
291
  headers?(node: OperationNode, param: ParameterNode): string
292
+ cookies?(node: OperationNode, param: ParameterNode): string
287
293
  }
288
294
  response?: {
289
295
  status?(node: OperationNode, statusCode: StatusCode): string
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-zod",
3
- "version": "5.9.0",
3
+ "version": "5.9.1",
4
4
  "description": "Generate Zod validation schemas with Kubb for runtime data parsing and type safety. Pairs with @kubb/plugin-ts for end-to-end type coverage.",
5
5
  "keywords": [
6
6
  "code-generation",
@@ -69,8 +69,8 @@
69
69
  "registry": "https://registry.npmjs.org/"
70
70
  },
71
71
  "dependencies": {
72
- "@kubb/kit": "^5.18.6",
73
- "@kubb/renderer-jsx": "^5.18.6"
72
+ "@kubb/kit": "^5.18.8",
73
+ "@kubb/renderer-jsx": "^5.18.8"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@internals/shared": "0.0.0",