Skip to content

Zod v4 generator should emit top-level string format schemas instead of deprecated string methods #3472

@quick007

Description

@quick007

Description

When generating Zod schemas for OpenAPI string formats with Zod v4, Orval currently emits legacy/deprecated string method syntax such as zod.string().uuid().

In Zod v4, string format validators were moved to top-level APIs. The old method forms still work, but Zod documents them as deprecated/legacy.

This causes projects using Zod v4 to get deprecation warnings from generated code, which users cannot cleanly fix without post-processing Orval output or maintaining a custom generator patch.

Output client

zod

Configuration (orval.config)

import { defineConfig } from "orval";

export default defineConfig({
  xxxx: {
    input: "https://localhost:5000/openapi/v1.json",
    output: {
      target: "./xxxx.ts",
      client: "react-query",
      httpClient: "fetch",
      baseUrl: {
        runtime: "env.VITE_API_BASE_URL",
        imports: [{ name: "env", importPath: "../env" }],
      },
      override: {
        fetch: {
          includeHttpResponseReturnType: false,
        },
      },
    },
  },
  xxx: {
    input: "https://localhost:5000/openapi/v1.json",
    output: {
      target: "./xxx.ts",
      client: "zod",
    },
  },
});

Environment

Run the command above and paste the output here.

Expected behavior

When the generated target is Zod v4, Orval should emit modern top-level format APIs where available.

For example:

export const example = zod.object({
  id: zod.uuid(),
  createdAt: zod.iso.datetime(),
});

Zod v3 generation can keep the current method-chain output, for example zod.string().uuid().

Actual behavior

Orval generates deprecated/legacy Zod v4 string method syntax, for example:

zod.string().uuid()
zod.string().datetime()

OpenAPI document (minimal, if applicable)

openapi: 3.0.3
info:
  title: Demo
  version: 0.0.0
paths: {}
components:
  schemas:
    Example:
      type: object
      properties:
        id:
          type: string
          format: uuid
        createdAt:
          type: string
          format: date-time

Additional context

Zod v4 migration guide: https://zod.dev/v4/changelog?id=drops-symbol-support

The guide documents that string format APIs such as z.email(), z.uuid(), and z.url() are now top-level APIs. Method forms like z.string().email() still exist for compatibility but are deprecated/legacy

Metadata

Metadata

Assignees

No one assigned

    Labels

    zodZod schema client related issue

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions