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.
Files changed (39) hide show
  1. package/README.md +6 -4
  2. package/lib-commonjs/index.js +691 -285
  3. package/lib-esm/{index.js → index.mjs} +691 -285
  4. package/lib-types/create/components.d.ts +25 -2
  5. package/lib-types/create/schema/index.d.ts +19 -12
  6. package/lib-types/create/schema/metadata.d.ts +2 -1
  7. package/lib-types/create/schema/parsers/array.d.ts +2 -3
  8. package/lib-types/create/schema/parsers/boolean.d.ts +2 -2
  9. package/lib-types/create/schema/parsers/brand.d.ts +2 -3
  10. package/lib-types/create/schema/parsers/catch.d.ts +2 -3
  11. package/lib-types/create/schema/parsers/date.d.ts +2 -2
  12. package/lib-types/create/schema/parsers/default.d.ts +2 -3
  13. package/lib-types/create/schema/parsers/discriminatedUnion.d.ts +2 -2
  14. package/lib-types/create/schema/parsers/enum.d.ts +2 -2
  15. package/lib-types/create/schema/parsers/index.d.ts +2 -3
  16. package/lib-types/create/schema/parsers/intersection.d.ts +2 -3
  17. package/lib-types/create/schema/parsers/lazy.d.ts +2 -3
  18. package/lib-types/create/schema/parsers/literal.d.ts +2 -2
  19. package/lib-types/create/schema/parsers/manual.d.ts +2 -3
  20. package/lib-types/create/schema/parsers/nativeEnum.d.ts +2 -3
  21. package/lib-types/create/schema/parsers/null.d.ts +2 -2
  22. package/lib-types/create/schema/parsers/nullable.d.ts +2 -3
  23. package/lib-types/create/schema/parsers/number.d.ts +2 -2
  24. package/lib-types/create/schema/parsers/object.d.ts +14 -6
  25. package/lib-types/create/schema/parsers/optional.d.ts +9 -4
  26. package/lib-types/create/schema/parsers/pipeline.d.ts +2 -3
  27. package/lib-types/create/schema/parsers/preprocess.d.ts +2 -3
  28. package/lib-types/create/schema/parsers/readonly.d.ts +2 -3
  29. package/lib-types/create/schema/parsers/record.d.ts +2 -3
  30. package/lib-types/create/schema/parsers/refine.d.ts +2 -3
  31. package/lib-types/create/schema/parsers/set.d.ts +2 -3
  32. package/lib-types/create/schema/parsers/string.d.ts +2 -2
  33. package/lib-types/create/schema/parsers/transform.d.ts +9 -4
  34. package/lib-types/create/schema/parsers/tuple.d.ts +2 -3
  35. package/lib-types/create/schema/parsers/union.d.ts +2 -3
  36. package/lib-types/create/schema/parsers/unknown.d.ts +2 -2
  37. package/lib-types/extendZod.d.ts +1 -1
  38. package/lib-types/openapi3-ts/dist/model/openapi31.d.ts +4 -0
  39. 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. Make a side-effectful import at the top of your entry point(s).
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/:a': {
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/:a': {
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 `output`. 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 use this when you know your transform has not changed the type.
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