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

String format is ignored in arrays #238

Closed guyariely closed 1 month ago

guyariely commented 11 months ago

Describe the bug String format (for example date, url, email, etc.) is ignored when it's an item in an array.

Minimal reproduction A minimal OAS document to show this:

openapi: 3.0.0
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: 'http://petstore.swagger.io/v1'
paths:
  /example:
    parameters: []
    get:
      summary: Example
      tags: []
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  date:
                    type: string
                    format: date-time
                  dates:
                    type: array
                    items:
                      type: string
                      format: date-time
                required:
                  - date
                  - dates

The output is:

const endpoints = makeApi([
  {
    method: "get",
    path: "/example",
    alias: "getExample",
    requestFormat: "json",
    response: z
      .object({
        date: z.string().datetime({ offset: true }),
        dates: z.array(z.string()),
      })
      .passthrough(),
  },
]);

Expected behavior

When a string is an item in an array it should still have format validation.