Skip to content

Conversation

darkbasic
Copy link

{
  type: 'string',
  format: 'binary',
  contentMediaType: 'application/octet-stream',
  maxLength: 20480
}
 const StoreChecklistTemplateRequest = z
-  .object({ description: z.string().max(255), file: z.instanceof(File).max(10240) })
+  .object({ description: z.string().max(255), file: z.instanceof(File) })
   .passthrough()

When there is a maxLength prop openapi-zod-client automatically adds the max operator to ensure the number of characters is appropriate. Unfortunately this won't generate valid zod code whenever the format is of type binary because max is not a valid method for File (Property 'max' does not exist on type 'ZodType<File, ZodTypeDef, File>').

This patch conditionally removes max for binary formats.

I thought about changing it with something like the following:

`.refine(file => file.size <= ${schema.maxLength} * 1024, {
  message: "File must be smaller than ${schema.maxLength}KB",
})`

but I'm not sure whether the openapi specs means bytes, KB, characters or what else whenever you specify maxLength in a binary format.

Copy link

vercel bot commented Jul 11, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
openapi-zod-client-rim4 Ready Ready Preview Comment Sep 24, 2025 5:37pm

@darkbasic
Copy link
Author

I've added a regression test to prevent future occurrences.

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

Successfully merging this pull request may close these issues.

1 participant