astahmer / openapi-zod-client

Generate a zodios (typescript http client with zod validation) from an OpenAPI spec (json/yaml)
openapi-zod-client.vercel.app
734 stars 82 forks source link

Zod schema mismatch from the contracts (missing `.nullable()`) #217

Open PeterMK85 opened 1 year ago

PeterMK85 commented 1 year ago

Describe the bug

Minimal reproduction Example

OpenApi:

   Example:
      description: 'Array of daily data points [[epoch-millis, metric-value], ..., [epoch-millis, metric-value]]. Data quality issues can cause the metric value to be null.'
      additionalProperties: false
      type: array
      items:
        additionalProperties: false
        type: array
        minItems: 2
        maxItems: 2
        items:
          type: number
          nullable: true
          readOnly: true
        readOnly: true
      readOnly: true

Zod:

const Example = z.array(z.array(z.number()));

Expected behavior Zod:

const Example = z.array(z.array(z.number().nullable()));

Additional context It seems the generated type properly reflects the type

type Example = Array<Array<number | null>>
humphd commented 2 months ago

We're also running into this, and I'm wondering how big of a fix it is?