Skip to content

Releases: samchungy/zod-openapi

v2.13.0

05 Feb 12:53
7510dab
Compare
Choose a tag to compare

What's Changed

New Features 🎉

  • Introduce same effectType by @samchungy in #217

    This library now has a new effectType when dealing with Zod Effects. In most scenarios, our users were using transform to sanitise or transform while ensuring the type did not change, however, this library could not handle this.

    The new same option allows this library to pick the input Zod Type to produce a schema while ensuring that the input and output remain the same type.

    For example: when creating a response (output) schema for the following type this library cannot hook into the TypeScript
    compiler at runtime to understand that you wanted a string schema generated:

    z.string().transform((string) => string.toUpperCase());

    which meant that you had to declare the following in order to get it to work:

    z.string().transform((string) => string.toUpperCase()).openapi({ effectType: 'input' });
    
    // or
    
    z.string().transform((string) => string.toUpperCase()).pipe(z.string());

    However, in the first example this could be dangerous if a user was to change the transform to no longer be the same type:

    z.string().transform((string) => string.length).openapi({ effectType: 'input' });

    The new same type allows us to avoid this mistake:

     z.string().transform((string) => string.toUpperCase()).openapi({ effectType: 'same' });
    
    // Type '"same"' is not assignable to type 'CreationType | undefined'. ts(2322)
     z.string().transform((string) => string.length).openapi({ effectType: 'same' });
  • Refactor Effect Handling by @samchungy in #211, #214

    This library now validates that effects used within registered Lazy schemas are not included in both input and output schemas. This could possibly be a breaking change if you were accidentally doing this.

    This library should also provide clearer errors when using Zod Effects with registered components which should make it easier to deal with effects.

    Before:

    Error: {"_def":{"in":{"_def":{"checks":[],"typeName":"ZodString","coerce":false}},"out":{"_def":{"checks":[],"typeName":"ZodNumber","coerce":false}},"typeName":"ZodPipeline","openapi":{"description":"A name that describes the job","example":"Mid level developer"}}} at /job > post > request body > content > application/json > schema > property: title contains a transformation but is used in both an input and an output. This is likely a mistake. Set an `effectType`, wrap it in a ZodPipeline or assign it a manual type to resolve

    After:

    Error: The ZodPipeline at /job > post > request body > content > application/json > schema > property: title is used within a registered compoment schema (jobTitle) and contains an output transformation (ZodPipeline) defined at /job > get > responses > 200 > content > application/json > schema > property: title which is also used in an input schema.
    
    This may cause the schema to render incorrectly and is most likely a mistake. You can resolve this by:
    
    1. Setting an `effectType` on the transformation to `same` or `input` eg. `.openapi({type: 'same'})`
    2. Wrapping the transformation in a ZodPipeline
    3. Assigning a manual type to the transformation eg. `.openapi({type: 'string'})`
    4. Removing the transformation
    5. Deregistering the component containing the transformation
  • Add default as an effect by @samchungy in #215, #216

    #175 added a change which would generate differences in the schema for input and outputs for a default schema. This may be a breaking change if you were using .default() in a registered schema which is referenced in both a request and response schema. As such, effectType can now also be used to change the rendered type.

Other Changes

  • Fix ESM importing on Node.js by @jaens in #208
  • Fix duplicate parameter component check by @jaens in #207
  • Remove duplicate descriptions on referenced schemas by @samchungy in #212

New Contributors

Full Changelog: v2.12.0...v2.13.0

v2.12.0

08 Jan 00:04
cc1d088
Compare
Choose a tag to compare

What's Changed

New Features 🎉

Other Changes

New Contributors

Full Changelog: v2.11.0...v2.12.0

v2.11.0

09 Nov 04:14
7edaf80
Compare
Choose a tag to compare

What's Changed

New Features 🎉

  • Fix Nullable Behaviour by @samchungy in #187

    .nullable() now renders differently for OpenAPI < 3.1.0

    Previously a registered schema which was made nullable would render as:

    {
      oneOf: [
        { $ref: '#/components/schemas/a' },
        { nullable: true }
      ]
    }

    will now be rendered as:

    {
      allOf: [
        { $ref: '#/components/schemas/a' }
      ],
      nullable: true
    }

    Similarly with nullable unions

    {
      anyOf: [
        { $ref: '#/components/schemas/a' },
        { $ref: '#/components/schemas/b' },
        { nullable: true }
      ]
    }

    Will now be rendered as:

    {
      anyOf: [
        { $ref: '#/components/schemas/a' },
        { $ref: '#/components/schemas/b' }
      ],
      nullable: true
    }

Full Changelog: v2.10.0...v2.11.0

v2.10.0

03 Nov 08:20
b811e96
Compare
Choose a tag to compare

What's Changed

New Features 🎉

  • Add unionOneOf by @samchungy in #184

    You can now use unionOneOf to override the output of a ZodUnion to be a oneOf schema instead of allOf (default). Previously rendering an oneOf schema was only possible with a ZodDiscriminatedUnion.

  • Bundle Package with esbuild by @samchungy in #178

    This should result in no changes to the public API, however, if you were previously reaching into the package paths internally you will now see an error.

Full Changelog: v2.9.1...v2.10.0

v2.10.0-beta.1

21 Oct 04:50
cdee275
Compare
Choose a tag to compare
v2.10.0-beta.1 Pre-release
Pre-release

What's Changed

New Features 🎉

  • Bundle Package with esbuild by @samchungy in #178

    This should result in no changes to the public API, however, if you were previously reaching into the internal files you will now see an error.

Full Changelog: v2.9.1...v2.10.0-beta.1

v2.9.1

16 Oct 13:38
3531b53
Compare
Choose a tag to compare

What's Changed

Other Changes

  • fix: default should be nonoptional in output state by @tomwwright in #175

    When .default() is used on a ZodObject property field in a response schema, it is now correctly reflected as a required field.

New Contributors

Full Changelog: v2.9.0...v2.9.1

v2.9.0

24 Aug 06:13
3525d79
Compare
Choose a tag to compare

What's Changed

New Features 🎉

  • Handle .startsWith(), .endsWith(), .includes() and multiple string patterns by @samchungy in #164

Other Changes

Full Changelog: v2.8.0...v2.9.0

v2.9.0-beta.0

24 Aug 05:43
b10481c
Compare
Choose a tag to compare
v2.9.0-beta.0 Pre-release
Pre-release

What's Changed

New Features 🎉

  • Handle .startsWith(), .endsWith(), .includes() and multiple string patterns by @samchungy in #164

Other Changes

Full Changelog: v2.8.0...v2.9.0-beta.0

v2.8.0

15 Aug 00:14
1b52ce5
Compare
Choose a tag to compare

What's Changed

New Features 🎉

Other Changes

Full Changelog: v2.7.4...v2.8.0

v2.7.4

18 Jul 00:28
6657e9c
Compare
Choose a tag to compare

What's Changed

Other Changes

Full Changelog: v2.7.3...v2.7.4