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

Problem with generating Zod validation for form data #1741

Open
RomanKuzo opened this issue Dec 10, 2024 · 0 comments
Open

Problem with generating Zod validation for form data #1741

RomanKuzo opened this issue Dec 10, 2024 · 0 comments
Labels
zod Zod related issue

Comments

@RomanKuzo
Copy link

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

@melloware melloware added the zod Zod related issue label Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
zod Zod related issue
Projects
None yet
Development

No branches or pull requests

2 participants