zod-openapi 2.11.0 → 2.13.0
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 +6 -4
- package/lib-commonjs/index.js +691 -285
- package/lib-esm/{index.js → index.mjs} +691 -285
- package/lib-types/create/components.d.ts +25 -2
- package/lib-types/create/schema/index.d.ts +19 -12
- package/lib-types/create/schema/metadata.d.ts +2 -1
- package/lib-types/create/schema/parsers/array.d.ts +2 -3
- package/lib-types/create/schema/parsers/boolean.d.ts +2 -2
- package/lib-types/create/schema/parsers/brand.d.ts +2 -3
- package/lib-types/create/schema/parsers/catch.d.ts +2 -3
- package/lib-types/create/schema/parsers/date.d.ts +2 -2
- package/lib-types/create/schema/parsers/default.d.ts +2 -3
- package/lib-types/create/schema/parsers/discriminatedUnion.d.ts +2 -2
- package/lib-types/create/schema/parsers/enum.d.ts +2 -2
- package/lib-types/create/schema/parsers/index.d.ts +2 -3
- package/lib-types/create/schema/parsers/intersection.d.ts +2 -3
- package/lib-types/create/schema/parsers/lazy.d.ts +2 -3
- package/lib-types/create/schema/parsers/literal.d.ts +2 -2
- package/lib-types/create/schema/parsers/manual.d.ts +2 -3
- package/lib-types/create/schema/parsers/nativeEnum.d.ts +2 -3
- package/lib-types/create/schema/parsers/null.d.ts +2 -2
- package/lib-types/create/schema/parsers/nullable.d.ts +2 -3
- package/lib-types/create/schema/parsers/number.d.ts +2 -2
- package/lib-types/create/schema/parsers/object.d.ts +14 -6
- package/lib-types/create/schema/parsers/optional.d.ts +9 -4
- package/lib-types/create/schema/parsers/pipeline.d.ts +2 -3
- package/lib-types/create/schema/parsers/preprocess.d.ts +2 -3
- package/lib-types/create/schema/parsers/readonly.d.ts +2 -3
- package/lib-types/create/schema/parsers/record.d.ts +2 -3
- package/lib-types/create/schema/parsers/refine.d.ts +2 -3
- package/lib-types/create/schema/parsers/set.d.ts +2 -3
- package/lib-types/create/schema/parsers/string.d.ts +2 -2
- package/lib-types/create/schema/parsers/transform.d.ts +9 -4
- package/lib-types/create/schema/parsers/tuple.d.ts +2 -3
- package/lib-types/create/schema/parsers/union.d.ts +2 -3
- package/lib-types/create/schema/parsers/unknown.d.ts +2 -2
- package/lib-types/extendZod.d.ts +1 -1
- package/lib-types/openapi3-ts/dist/model/openapi31.d.ts +4 -0
- package/package.json +14 -8
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ yarn add zod zod-openapi
|
|
|
29
29
|
|
|
30
30
|
### `extendZodWithOpenApi`
|
|
31
31
|
|
|
32
|
-
This mutates Zod to add an extra `.openapi()` method.
|
|
32
|
+
This mutates Zod to add an extra `.openapi()` method. Call this at the top of your entry point(s).
|
|
33
33
|
|
|
34
34
|
```typescript
|
|
35
35
|
import { z } from 'zod';
|
|
@@ -182,7 +182,7 @@ Query, Path, Header & Cookie parameters can be created using the `requestParams`
|
|
|
182
182
|
```typescript
|
|
183
183
|
createDocument({
|
|
184
184
|
paths: {
|
|
185
|
-
'/jobs
|
|
185
|
+
'/jobs/{a}': {
|
|
186
186
|
put: {
|
|
187
187
|
requestParams: {
|
|
188
188
|
path: z.object({ a: z.string() }),
|
|
@@ -201,7 +201,7 @@ If you would like to declare parameters in a more traditional way you may also d
|
|
|
201
201
|
```ts
|
|
202
202
|
createDocument({
|
|
203
203
|
paths: {
|
|
204
|
-
'/jobs
|
|
204
|
+
'/jobs/{a}': {
|
|
205
205
|
put: {
|
|
206
206
|
parameters: [
|
|
207
207
|
z.string().openapi({
|
|
@@ -334,7 +334,7 @@ _Input_: Request Bodies, Request Parameters, Headers
|
|
|
334
334
|
|
|
335
335
|
_Output_: Responses, Response Headers
|
|
336
336
|
|
|
337
|
-
If a registered schema with a transform or pipeline is used in both a request and response schema you will receive an error because the created schema for each will be different. To override the creation type for a specific ZodEffect, add an `.openapi()` field on it and set the `effectType` field to `input` or `
|
|
337
|
+
If a registered schema with a transform or pipeline is used in both a request and response schema you will receive an error because the created schema for each will be different. To override the creation type for a specific ZodEffect, add an `.openapi()` field on it and set the `effectType` field to `input`, `output` or `same`. This will force this library to always generate the input/output type even if we are creating a response (output) or request (input) type. You typically want to set this when you know the type has not changed in the transform. `same` is the recommended choice as it will throw a type error if the input and output types in the transform drift.
|
|
338
338
|
|
|
339
339
|
`.preprocess()` will always return the `output` type even if we are creating an input schema. If a different input type is required you can achieve this with a `.transform()` combined with a `.pipe()` or simply declare a manual `type` in `.openapi()`.
|
|
340
340
|
|
|
@@ -521,6 +521,7 @@ For example in `z.string().nullable()` will be rendered differently
|
|
|
521
521
|
- ZodLiteral
|
|
522
522
|
- ZodNativeEnum
|
|
523
523
|
- supporting `string`, `number` and combined enums.
|
|
524
|
+
- ZodNever
|
|
524
525
|
- ZodNull
|
|
525
526
|
- ZodNullable
|
|
526
527
|
- ZodNumber
|
|
@@ -543,6 +544,7 @@ For example in `z.string().nullable()` will be rendered differently
|
|
|
543
544
|
- ZodTuple
|
|
544
545
|
- `items` mapping for `.rest()`
|
|
545
546
|
- `prefixItems` mapping for OpenAPI 3.1.0+
|
|
547
|
+
- ZodUndefined
|
|
546
548
|
- ZodUnion
|
|
547
549
|
- By default it outputs an `allOf` schema. Use `unionOneOf` to change this to output `oneOf` instead.
|
|
548
550
|
- ZodUnknown
|