Skip to content

Releases: samchungy/zod-openapi

v4.2.2

25 Dec 01:28
630afa2
Compare
Choose a tag to compare

What's Changed

Other Changes

Full Changelog: v4.2.1...v4.2.2

v4.2.2-beta.0

25 Dec 01:21
ed32c20
Compare
Choose a tag to compare
v4.2.2-beta.0 Pre-release
Pre-release

What's Changed

Other Changes

Full Changelog: v4.2.1...v4.2.2-beta.0

v4.2.1

20 Dec 13:46
22dc62f
Compare
Choose a tag to compare

What's Changed

Other Changes

  • Replace current and previous properties with symbols to allow JSON serialization of zod schema by @alon-gb in #393

New Contributors

Full Changelog: v4.2.0...v4.2.1

v4.2.0

16 Dec 23:31
d6e5da7
Compare
Choose a tag to compare

What's Changed

New Features 🎉

  • Add IP format support by @samchungy in #387

    This adds ipv4 and ipv6 string format mapping for .ip({ version: 'v4' }), .ip({ version: 'v6' }), .cidr({ version: 'v4' }), .cidr({ version: 'v6' })

Other Changes

Full Changelog: v4.1.2...v4.2.0

v4.1.2

15 Dec 23:11
f6d2094
Compare
Choose a tag to compare

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

14 Dec 13:07
991e523
Compare
Choose a tag to compare

What's Changed

Other Changes

  • Update example types by @samchungy in #374

    This updates the example and examples types to allow for strings for a ZodDate schema and also disallows undefined from being passed to the examples array.

Full Changelog: v4.1.0...v4.1.1

v4.1.0

25 Nov 02:08
87f69cc
Compare
Choose a tag to compare

What's Changed

New Features 🎉

New Contributors

Full Changelog: v4.0.0...v4.1.0

v4.0.0

10 Nov 05:51
1d960e9
Compare
Choose a tag to compare

What's Changed

Breaking Changes 🛠

  • .openapi() Breaking Change by @samchungy in #356

    .openapi() behaves a little differently now. It will now preserve previous openapi state except for ref 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 declare zod-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?

    1. 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 of description.

      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.

    2. 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 #358

    z.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 of allOf.

Full Changelog: v3.3.0...v4.0.0

v4.0.0-beta.0

10 Nov 05:35
06ac04c
Compare
Choose a tag to compare
v4.0.0-beta.0 Pre-release
Pre-release
Release v4.0.0-beta.0

v3.3.0

30 Oct 11:00
4639070
Compare
Choose a tag to compare

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