Releases: samchungy/zod-openapi
v4.2.2
What's Changed
Other Changes
- Fix Manual Type Extensions by @samchungy in #398
Full Changelog: v4.2.1...v4.2.2
v4.2.2-beta.0
What's Changed
Other Changes
- Fix Manual Type Extensions by @samchungy in #398
Full Changelog: v4.2.1...v4.2.2-beta.0
v4.2.1
v4.2.0
What's Changed
New Features 🎉
-
Add IP format support by @samchungy in #387
This adds
ipv4
andipv6
stringformat
mapping for.ip({ version: 'v4' })
,.ip({ version: 'v6' })
,.cidr({ version: 'v4' })
,.cidr({ version: 'v6' })
Other Changes
- Export getZodObject via zod-openapi/api by @samchungy in #389
Full Changelog: v4.1.2...v4.2.0
v4.1.2
What's Changed
Other Changes
-
Fix omit/pick bug by @samchungy in #383
This fixes a bug introduced in 4.0.0 as part of the base registered schema behaviour changes. This caused the library to incorrectly generate base schemas for registered schemas which had
.omit()
and.pick()
used on them.
Full Changelog: v4.1.1...v4.1.2
v4.1.1
What's Changed
Other Changes
-
Update example types by @samchungy in #374
This updates the
example
andexamples
types to allow for strings for a ZodDate schema and also disallowsundefined
from being passed to theexamples
array.
Full Changelog: v4.1.0...v4.1.1
v4.1.0
What's Changed
New Features 🎉
- Add support for bigint by @mdoi2 in #366
- Add enforceDiscriminatedUnionComponents by @samchungy in #369
New Contributors
- @kkogovsek made their first contribution in #367
Full Changelog: v4.0.0...v4.1.0
v4.0.0
What's Changed
Breaking Changes 🛠
-
.openapi()
Breaking Change by @samchungy in #356.openapi()
behaves a little differently now. It will now preserveprevious
openapi state except forref
and use it. This means that any metadata set on previous schema will now also be carried over to the next schema. Whilst I don't suspect this will impact too many users, it is still a breaking change nonetheless. Libraries which declarezod-openapi
as a peer dependency, can safely set this version as a non breaking change for their library.const FooSchema = z .string() .transform((str => str.trim())) .openapi({ effectType: 'same', example: 'foo' }); // in this version, this BarSchema now has `effectType: same` and `example: 'foo'` too const BarSchema = FooSchema.openapi({ description: "bar" });
Why do we need this change?
-
Unintuitive Extension
const FooSchema = z.string().openapi({ ref: 'string' }); const BarSchema = z.object({ a: FooSchema, b: FooSchema.openapi({ description: 'foo' }), }); createSchema(BarSchema)
This previous generated the following:
{ schema: { type: 'object', properties: { a: { '$ref': '#/components/schemas/string' }, b: { type: 'string', description: 'foo' } }, required: [ 'a', 'b' ] }, components: { string: { type: 'string' } } }
However, it's clear that the user simply wanted to reuse the FooSchema but describe it as something else later on.
After:
{ schema: { type: 'object', properties: { a: { '$ref': '#/components/schemas/string' }, b: { '$ref': '#/components/schemas/string', description: 'foo' } }, required: [ 'a', 'b' ] }, components: { string: { type: 'string' } } }
This also fixes an issue with the following example where
.describe()
is used in place ofdescription
.const FooSchema = z.string().openapi({ ref: 'string' }); const BarSchema = z.object({ a: FooSchema, b: FooSchema.describe('foo') }); createSchema(BarSchema)
This scenario previously caused us to throw an error because it attempts to register the FooSchema twice with different objects.
-
Unregistered Base Schemas.
Previously, if you were to use a schema like this, it would actually render an incorrect component. This change updates that behaviour to always generate the base schema as a component.
Before:
const FooSchema = z.string().uuid().openapi({ ref: 'id' }); const BarSchema = FooSchema.describe('unique job id'); createSchema(BarSchema);
{ schema: { '$ref': '#/components/schemas/id' }, components: { id: { type: 'string', format: 'uuid', description: 'unique job id' } } }
After:
{ schema: { '$ref': '#/components/schemas/id', description: 'unique job id' }, components: { id: { type: 'string', format: 'uuid' } } }
This change also updates some of the parsing logic for registered schemas with a
description
field.Before
{ 'allOf': [ '$ref': '#/components/schemas/foo', { "description": "bar"} ], ] }
After in 3.1.0
{ '$ref': '#/components/schemas/foo', 'description': 'bar', }
After in 3.0.0
{ 'allOf': [ '$ref': '#/components/schemas/foo', ], 'description': 'bar' }
The nesting of additional fields alongside
allOf
has also been adjusted.
-
New Features 🎉
-
Add
multipleOf
support by @samchungy in #358z.number().multipleOf(3);
Should now generate the following:
{ type: 'number', multipleOf: 3, }
-
Update Intersection Parser by @samchungy in #360
This library will now attempt to
flatten
any intersection chains you may have which will reduce unnecessary nesting ofallOf
.
Full Changelog: v3.3.0...v4.0.0
v4.0.0-beta.0
Release v4.0.0-beta.0
v3.3.0
What's Changed
Minor Breaking Change
ZodCatch
is now properly treated as a Zod Effect. This is because ZodCatch
can take any invalid result, such as an undefined
and transform it. As a result, we now treat it the same as a ZodDefault
when it comes to schema generation.
Required Logic Changes
The way we determine if schemas are optional has been simplified and under the hood runs a .safeParse(undefined)
with the schema we are checking. This removes the double traversal of the schema and has highlighted a couple errors in the schema generation.
ZodCustom
should now be flagged properly as required
when a validating function is passed to it. Thanks @pmsfc
ZodUnion
can now accept z.undefined()
, z.literal(undefined)
, z.never()
values.
ZodObject
can now accept z.literal(undefined)
as a value.
New Contributors
Full Changelog: v3.2.0...v3.3.0