Skip to content
Sarj Code Standards

require-constrained-schema-integer

Declare integer and lower-bound validation for numeric limit and version schema fields.

Why

A bare number schema accepts fractions and negative limits or versions. Encoding the domain in validation makes downstream arithmetic and pagination contracts explicit.

Fix

Use an integer schema with a positive lower bound for limit and a nonnegative lower bound for version, or reuse an existing named domain schema.

Examples

Before — flagged A number is broader than a limit
src/options.ts
import { z } from "zod";
const OptionsSchema = z.object({ limit: z.number() });
After — preferred Declare the numeric domain
src/options.ts
import { z } from "zod";
const OptionsSchema = z.object({
limit: z.number().int().positive(),
version: z.int().nonnegative(),
});