fix(zod): enforce integer validation - #3737
Conversation
📝 WalkthroughWalkthroughThe Zod generator now preserves OpenAPI ChangesInteger-aware Zod generation
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
melloware
left a comment
There was a problem hiding this comment.
looks like build failed?
|
The CI failure was unrelated to this PR: during sample generation, the |
…ce and add coercion tests
b7abaf4 to
49d019d
Compare
|
Running now |
@orval/angular
@orval/axios
@orval/core
@orval/effect
@orval/fetch
@orval/hono
@orval/mcp
@orval/mock
orval
@orval/query
@orval/solid-start
@orval/swr
@orval/zod
commit: |
Summary
integerschemasz.int()for Zod 4 and Zod Mini while preservingz.number().int()for Zod 3Behavior
Fractional values are now rejected for OpenAPI
integerschemas. Zod 4 and Zod Mini use the nativez.int()safe-integer semantics; Zod 3 retains its nativez.number().int()behavior.Breaking behavior
z.int()enforces JavaScript safe integer bounds. Integer fields withformat: int64that carry values aboveNumber.MAX_SAFE_INTEGER(for example 64-bit snowflake ids) were accepted by the previousz.number()output and are now rejected. The Zod 3 output (z.number().int()) still accepts them. Note thatJSON.parsealready loses precision for such values, so rejecting them surfaces a real problem; APIs that need full 64-bit range should serialize those fields as strings or use an override.zodParamsmutator authors: integer fields now surface the new validator nameint. On Zod 4 and Zod Mini without coercion the mutator is called withintinstead ofnumber; on Zod 3 and on coerced output it is called with bothnumberandint.Test plan
vp lint packages/zod/src/index.ts packages/zod/src/zod.test.ts packages/orval/src/reusable-schemas.test.tsvitest run packages/zod/src packages/orval/src/reusable-schemas.test.tstsc --noEmit -p packages/zod/tsconfig.jsontsc --noEmit -p packages/orval/tsconfig.jsonvp run -w test:snapshotsFixes #3736
Summary by CodeRabbit
int) for OpenAPItype: "integer", including correct min/max constraint handling and support across different Zod emission modes (including coercion and lightweight variants).