Skip to content

Problem with generating Zod validation for form data #1741

@RomanKuzo

Description

@RomanKuzo

What are the steps to reproduce this issue?

  1. Use Swagger API docs where there is endpoint that use form-data as request body
  2. Try to generate api with orval.

What happens?

There is no zod validation scheme for the request body that uses form data

What were you expecting to happen?

I want to have something like this

export const createPostSchema = z.object({
  file: z.instanceof(File), // Validate file as a File object
  name: z.string(), // Name as a required string
  subtitle: z.string(), // Subtitle as a required string
  text: z.string(), // Text as a required string
  publishedAt: z.string().datetime(), // ISO 8601 date-time validation
  status: z.boolean(), // Boolean validation
  store: z.number().int(), // Integer validation
  fixed: z.boolean(), // Boolean validation
  imageAlt: z.string().optional(), // Optional string
  postTags: z.array(z.number().int()), // Array of integers
});

Any logs, error output, etc?

No

Any other comments?

There is no any problems with other endpoints that don’t use form data. Orval generates for me request body zod validation successfully

Example:

export const postV1RolesCreateBody = zod.object({
  name: zod.string().min(1),
  title: zod.string().nullish(),
  rolePermissions: zod.array(
    zod.object({
      id: zod.number().optional(),
    })
  ),
});

What versions are you using?

NextJs version: 13, Node version: 20, Orval version: 7.3.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    zodZod related issue

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions