astahmer / openapi-zod-client

Generate a zodios (typescript http client with zod validation) from an OpenAPI spec (json/yaml)

Home Page:openapi-zod-client.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enum with a null value causes type error

BrandonGoren opened this issue · comments

Describe the bug
As of 1.11.1, the following command produces an enum that does not work with zod.

openapi-zod-client https://raw.githubusercontent.com/plaid/plaid-openapi/master/2020-09-14.yml -o src/generated/plaid-api-schemas.ts --export-schemas  
/** Has a type error **/
export const OwnershipType = z.enum([
  null,
  'individual',
  'joint',
  'association',
  'trust',
])

Minimal reproduction

OwnershipType:
    nullable: true
    type: string
    enum:
      - null
      - individual
      - joint
      - association
      - trust

Expected behavior
The z.enum should be nullable, and not include the null value.

I'm also bumping into this. Has anyone found a reliable workaround?