Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String format is ignored in arrays #238

Open
guyariely opened this issue Oct 4, 2023 · 0 comments
Open

String format is ignored in arrays #238

guyariely opened this issue Oct 4, 2023 · 0 comments

Comments

@guyariely
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant