diff --git a/lib/src/openApiToZod.test.ts b/lib/src/openApiToZod.test.ts index a24b3ab..4e037b9 100644 --- a/lib/src/openApiToZod.test.ts +++ b/lib/src/openApiToZod.test.ts @@ -459,3 +459,15 @@ test("CodeMeta with nested refs", () => { } `); }); + +test("binary string format with maxLength should not add max validation", () => { + // This prevents "Property 'max' does not exist on type 'ZodType'" errors + expect( + getSchemaAsZodString({ type: "object", properties: { file: { type: "string", format: "binary", maxLength: 20480 } } }) + ).toMatchInlineSnapshot('"z.object({ file: z.instanceof(File) }).partial().passthrough()"'); + + // For comparison: regular string with maxLength should have .max() + expect( + getSchemaAsZodString({ type: "object", properties: { text: { type: "string", maxLength: 20480 } } }) + ).toMatchInlineSnapshot('"z.object({ text: z.string().max(20480) }).partial().passthrough()"'); +}); diff --git a/lib/src/openApiToZod.ts b/lib/src/openApiToZod.ts index 73fb424..2d55a1e 100644 --- a/lib/src/openApiToZod.ts +++ b/lib/src/openApiToZod.ts @@ -383,7 +383,7 @@ const getZodChainableStringValidations = (schema: SchemaObject) => { validations.push(`min(${schema.minLength})`); } - if (schema.maxLength !== undefined) { + if (schema.maxLength !== undefined && schema.format !== "binary") { validations.push(`max(${schema.maxLength})`); } }