-
Notifications
You must be signed in to change notification settings - Fork 93
Description
Bug description
it seems the generated code doesn't compile.
i believe the code should check for int64 validity but preserve the type as string.
Input
interface Body {
/**
* The id of the order item to update.
* @format int64
*/
id: string;
}Expected output
not sure but i found this thread colinhacks/zod#330
also it seems zod supports int64 in v4 https://zod.dev/v4?id=number-formats
// Expected Zod schemasActual output
Property 'int64' does not exist on type 'ZodString'
// Actual Zod schemas
export const bodySchema = z.object({
id: z.string().int64(),
});Versions
- Typescript:
v5.9.2 - Zod:
v4.1.12
i think this is the solution:
import { z } from "zod";
export const int64String = z.string().refine((val) => {
try {
// Let zod do the int64 check
z.int64().parse(BigInt(val));
return true;
} catch {
return false;
}
}, {
message: "Must be a valid int64 string",
});
int64String.parse("123"); // OK
int64String.parse("9223372036854775807"); // OK
int64String.parse("9223372036854775808"); // ❌ outside int64
int64String.parse("abc"); // ❌ invalid
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels