Skip to content

[zod-openapi] - OpenAPI 3.0: the usage of nullish and nullable result in "type" null #211

Open
@RobbyUitbeijerse

Description

@RobbyUitbeijerse

Hi there!

Our team started using the latest version of the packages after the merger of #206 (thanks for that!)

We noticed a small issue (but quite consequential) when it comes to nullable properties. I'll try to explain what we're facing in an example, but also dropped a full diff of our spec after migrating to @anatine/zod-openapi. I'm currently assuming it's an issue only when using patchNestjsSwagger with 3.0.

Here's a schema:

export const ContinuationTokenSchema = z.object({
  continuation: z.string().nullish().default(null),
});

This schema results in the following OpenAPI output:

"continuation": {
   "default": null,
   "type": "null"
},

While we are actually expecting it to be:

"continuation": {
   "type": "string"
   "default: null, 
   "nullable": true
},

It happens for all sorts of schema: arrays, booleans, strings - below you will find a link to our OpenAPI spec after migrating to @anatine/zod-openapi

(left isnestjs-zod, right is @anatine/zod-openapi)
https://www.diffchecker.com/Zg4nfCdt/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions